title: Multivariate polynomial regression in javascript?
body: <p>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.</p>
  
  <p>The python way is to do it with sklearn.preprocessing.PolynomialFeatures, followed by a Linear Regression: <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html" rel="nofollow noreferrer">http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html</a></p>
  
  <p>The ml.js library only does simple polynomial regression, that is it can only take in a 1-D input and 1-D output. <a href="https://github.com/mljs/regression-polynomial" rel="nofollow noreferrer">https://github.com/mljs/regression-polynomial</a></p>
  
  <p>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.</p>
  
  <p>Here is example code:</p>
  
  <pre><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&lt;5; i++){ y.push(0); }
  for (i = 5; i&lt;10; i++){ y.push(1); }
  const poly = new PolynomialRegression(x, y, 2);
  console.log(poly.predict([[3,3],[4,4]]))
  </code></pre>
  
  <p>outputs</p>
  
  <pre><code>[ NaN, NaN ]
  </code></pre>