Multivariate polynomial regression in javascript?
How can multivariate linear regression be adapted to do multivariate polynomial regression in Javascript? This means that the input X is a 2-D array, predicting a y target that is a 1-D array.
The python way is to do it with sklearn.preprocessing.PolynomialFeatures, followed by a Linear Regression: http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html
The ml.js library only does simple polynomial regression, that is it can only take in a 1-D input and 1-D output. https://github.com/mljs/regression-polynomial
Here is an example of working code in Python scikit-learn for multivariate polynomial regression, where X is a 2-D array and y is a 1-D vector.
Here is example code:
const math = require('mathjs');
const PolynomialRegression = require('ml-regression-polynomial');
const a1 = math.random([10,2]);
const a2 = math.reshape(math.range(0, 20, 1), [10, 2]);
const x = math.add(a1, a2).valueOf();
const y = ;
for (i = 0; i<5; i++) y.push(0);
for (i = 5; i<10; i++) y.push(1);
const poly = new PolynomialRegression(x, y, 2);
console.log(poly.predict([[3,3],[4,4]]))
outputs
[ NaN, NaN ]
javascript node.js scikit-learn linear-regression polynomial-math
|
show 1 more comment
How can multivariate linear regression be adapted to do multivariate polynomial regression in Javascript? This means that the input X is a 2-D array, predicting a y target that is a 1-D array.
The python way is to do it with sklearn.preprocessing.PolynomialFeatures, followed by a Linear Regression: http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html
The ml.js library only does simple polynomial regression, that is it can only take in a 1-D input and 1-D output. https://github.com/mljs/regression-polynomial
Here is an example of working code in Python scikit-learn for multivariate polynomial regression, where X is a 2-D array and y is a 1-D vector.
Here is example code:
const math = require('mathjs');
const PolynomialRegression = require('ml-regression-polynomial');
const a1 = math.random([10,2]);
const a2 = math.reshape(math.range(0, 20, 1), [10, 2]);
const x = math.add(a1, a2).valueOf();
const y = ;
for (i = 0; i<5; i++) y.push(0);
for (i = 5; i<10; i++) y.push(1);
const poly = new PolynomialRegression(x, y, 2);
console.log(poly.predict([[3,3],[4,4]]))
outputs
[ NaN, NaN ]
javascript node.js scikit-learn linear-regression polynomial-math
Is it a possible solution to call Python from your code?
– James Phillips
Nov 5 '18 at 11:51
No, otherwise I would not be asking this question
– mikal94305
Nov 5 '18 at 23:06
Given the limited and immature libraries for machine learning in Javascript
what are you talking about?
– Michal
Nov 9 '18 at 18:12
The question needs more details. Can you show the code you used in sklearn? You usedPolynomialFeatures
on X (independent variables) ory
(dependent)? What was the shape ofX
andy
beforePolynomialFeatures
? Was it 1-d? The js library library linked does the same. It takes a 1-d X, generates polynomial upto specified degree, and use the new data to regress withy
. Why dont you use it? Have you used it? Have you seen the coefficients learnt by it? Or are you talking about a 2-dy
having multiple targets (dependents) in it?
– Vivek Kumar
Nov 13 '18 at 13:22
Multivariate means X is 2D
– mikal94305
Nov 15 '18 at 6:11
|
show 1 more comment
How can multivariate linear regression be adapted to do multivariate polynomial regression in Javascript? This means that the input X is a 2-D array, predicting a y target that is a 1-D array.
The python way is to do it with sklearn.preprocessing.PolynomialFeatures, followed by a Linear Regression: http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html
The ml.js library only does simple polynomial regression, that is it can only take in a 1-D input and 1-D output. https://github.com/mljs/regression-polynomial
Here is an example of working code in Python scikit-learn for multivariate polynomial regression, where X is a 2-D array and y is a 1-D vector.
Here is example code:
const math = require('mathjs');
const PolynomialRegression = require('ml-regression-polynomial');
const a1 = math.random([10,2]);
const a2 = math.reshape(math.range(0, 20, 1), [10, 2]);
const x = math.add(a1, a2).valueOf();
const y = ;
for (i = 0; i<5; i++) y.push(0);
for (i = 5; i<10; i++) y.push(1);
const poly = new PolynomialRegression(x, y, 2);
console.log(poly.predict([[3,3],[4,4]]))
outputs
[ NaN, NaN ]
javascript node.js scikit-learn linear-regression polynomial-math
How can multivariate linear regression be adapted to do multivariate polynomial regression in Javascript? This means that the input X is a 2-D array, predicting a y target that is a 1-D array.
The python way is to do it with sklearn.preprocessing.PolynomialFeatures, followed by a Linear Regression: http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html
The ml.js library only does simple polynomial regression, that is it can only take in a 1-D input and 1-D output. https://github.com/mljs/regression-polynomial
Here is an example of working code in Python scikit-learn for multivariate polynomial regression, where X is a 2-D array and y is a 1-D vector.
Here is example code:
const math = require('mathjs');
const PolynomialRegression = require('ml-regression-polynomial');
const a1 = math.random([10,2]);
const a2 = math.reshape(math.range(0, 20, 1), [10, 2]);
const x = math.add(a1, a2).valueOf();
const y = ;
for (i = 0; i<5; i++) y.push(0);
for (i = 5; i<10; i++) y.push(1);
const poly = new PolynomialRegression(x, y, 2);
console.log(poly.predict([[3,3],[4,4]]))
outputs
[ NaN, NaN ]
javascript node.js scikit-learn linear-regression polynomial-math
javascript node.js scikit-learn linear-regression polynomial-math
edited Nov 16 '18 at 23:26
mikal94305
asked Nov 4 '18 at 21:38
mikal94305mikal94305
99321231
99321231
Is it a possible solution to call Python from your code?
– James Phillips
Nov 5 '18 at 11:51
No, otherwise I would not be asking this question
– mikal94305
Nov 5 '18 at 23:06
Given the limited and immature libraries for machine learning in Javascript
what are you talking about?
– Michal
Nov 9 '18 at 18:12
The question needs more details. Can you show the code you used in sklearn? You usedPolynomialFeatures
on X (independent variables) ory
(dependent)? What was the shape ofX
andy
beforePolynomialFeatures
? Was it 1-d? The js library library linked does the same. It takes a 1-d X, generates polynomial upto specified degree, and use the new data to regress withy
. Why dont you use it? Have you used it? Have you seen the coefficients learnt by it? Or are you talking about a 2-dy
having multiple targets (dependents) in it?
– Vivek Kumar
Nov 13 '18 at 13:22
Multivariate means X is 2D
– mikal94305
Nov 15 '18 at 6:11
|
show 1 more comment
Is it a possible solution to call Python from your code?
– James Phillips
Nov 5 '18 at 11:51
No, otherwise I would not be asking this question
– mikal94305
Nov 5 '18 at 23:06
Given the limited and immature libraries for machine learning in Javascript
what are you talking about?
– Michal
Nov 9 '18 at 18:12
The question needs more details. Can you show the code you used in sklearn? You usedPolynomialFeatures
on X (independent variables) ory
(dependent)? What was the shape ofX
andy
beforePolynomialFeatures
? Was it 1-d? The js library library linked does the same. It takes a 1-d X, generates polynomial upto specified degree, and use the new data to regress withy
. Why dont you use it? Have you used it? Have you seen the coefficients learnt by it? Or are you talking about a 2-dy
having multiple targets (dependents) in it?
– Vivek Kumar
Nov 13 '18 at 13:22
Multivariate means X is 2D
– mikal94305
Nov 15 '18 at 6:11
Is it a possible solution to call Python from your code?
– James Phillips
Nov 5 '18 at 11:51
Is it a possible solution to call Python from your code?
– James Phillips
Nov 5 '18 at 11:51
No, otherwise I would not be asking this question
– mikal94305
Nov 5 '18 at 23:06
No, otherwise I would not be asking this question
– mikal94305
Nov 5 '18 at 23:06
Given the limited and immature libraries for machine learning in Javascript
what are you talking about?– Michal
Nov 9 '18 at 18:12
Given the limited and immature libraries for machine learning in Javascript
what are you talking about?– Michal
Nov 9 '18 at 18:12
The question needs more details. Can you show the code you used in sklearn? You used
PolynomialFeatures
on X (independent variables) or y
(dependent)? What was the shape of X
and y
before PolynomialFeatures
? Was it 1-d? The js library library linked does the same. It takes a 1-d X, generates polynomial upto specified degree, and use the new data to regress with y
. Why dont you use it? Have you used it? Have you seen the coefficients learnt by it? Or are you talking about a 2-d y
having multiple targets (dependents) in it?– Vivek Kumar
Nov 13 '18 at 13:22
The question needs more details. Can you show the code you used in sklearn? You used
PolynomialFeatures
on X (independent variables) or y
(dependent)? What was the shape of X
and y
before PolynomialFeatures
? Was it 1-d? The js library library linked does the same. It takes a 1-d X, generates polynomial upto specified degree, and use the new data to regress with y
. Why dont you use it? Have you used it? Have you seen the coefficients learnt by it? Or are you talking about a 2-d y
having multiple targets (dependents) in it?– Vivek Kumar
Nov 13 '18 at 13:22
Multivariate means X is 2D
– mikal94305
Nov 15 '18 at 6:11
Multivariate means X is 2D
– mikal94305
Nov 15 '18 at 6:11
|
show 1 more comment
1 Answer
1
active
oldest
votes
The ml.js estimator you referenced does exactly what you’re looking for. It expands your features within n degrees and then estimates a linear function using those features.
It’s just one step rather than two.
1
The ml.js polynomial regression only takes in 1D arrays, not 2D arrays; hence the question about multivariate regression, not simple regression.
– mikal94305
Nov 5 '18 at 23:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53145739%2fmultivariate-polynomial-regression-in-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The ml.js estimator you referenced does exactly what you’re looking for. It expands your features within n degrees and then estimates a linear function using those features.
It’s just one step rather than two.
1
The ml.js polynomial regression only takes in 1D arrays, not 2D arrays; hence the question about multivariate regression, not simple regression.
– mikal94305
Nov 5 '18 at 23:06
add a comment |
The ml.js estimator you referenced does exactly what you’re looking for. It expands your features within n degrees and then estimates a linear function using those features.
It’s just one step rather than two.
1
The ml.js polynomial regression only takes in 1D arrays, not 2D arrays; hence the question about multivariate regression, not simple regression.
– mikal94305
Nov 5 '18 at 23:06
add a comment |
The ml.js estimator you referenced does exactly what you’re looking for. It expands your features within n degrees and then estimates a linear function using those features.
It’s just one step rather than two.
The ml.js estimator you referenced does exactly what you’re looking for. It expands your features within n degrees and then estimates a linear function using those features.
It’s just one step rather than two.
edited Nov 5 '18 at 20:18
answered Nov 5 '18 at 15:43
John HJohn H
1,232415
1,232415
1
The ml.js polynomial regression only takes in 1D arrays, not 2D arrays; hence the question about multivariate regression, not simple regression.
– mikal94305
Nov 5 '18 at 23:06
add a comment |
1
The ml.js polynomial regression only takes in 1D arrays, not 2D arrays; hence the question about multivariate regression, not simple regression.
– mikal94305
Nov 5 '18 at 23:06
1
1
The ml.js polynomial regression only takes in 1D arrays, not 2D arrays; hence the question about multivariate regression, not simple regression.
– mikal94305
Nov 5 '18 at 23:06
The ml.js polynomial regression only takes in 1D arrays, not 2D arrays; hence the question about multivariate regression, not simple regression.
– mikal94305
Nov 5 '18 at 23:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53145739%2fmultivariate-polynomial-regression-in-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is it a possible solution to call Python from your code?
– James Phillips
Nov 5 '18 at 11:51
No, otherwise I would not be asking this question
– mikal94305
Nov 5 '18 at 23:06
Given the limited and immature libraries for machine learning in Javascript
what are you talking about?– Michal
Nov 9 '18 at 18:12
The question needs more details. Can you show the code you used in sklearn? You used
PolynomialFeatures
on X (independent variables) ory
(dependent)? What was the shape ofX
andy
beforePolynomialFeatures
? Was it 1-d? The js library library linked does the same. It takes a 1-d X, generates polynomial upto specified degree, and use the new data to regress withy
. Why dont you use it? Have you used it? Have you seen the coefficients learnt by it? Or are you talking about a 2-dy
having multiple targets (dependents) in it?– Vivek Kumar
Nov 13 '18 at 13:22
Multivariate means X is 2D
– mikal94305
Nov 15 '18 at 6:11