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 ]