title: Multivariate polynomial regression for python
body: <p>In extension of: <a href="https://stackoverflow.com/questions/34373606/scikit-learn-coefficients-polynomialfeatures">scikit learn coefficients polynomialfeatures</a></p>
  
  <p>What is a straightforward way of doing multivariate polynomial regression for python? </p>
  
  <p>Say, we have N samples with each 3 features and we have for each sample 40 (may as well be any number, of course, but it is 40 in my case) response variables. We want to make a function that relates the 3 independent variables to the 40 response variables. For this, we train a polynomial model on N-1 of our samples, and estimate the 40 response variables of the remaining one sample. The dimensionalities of independent variable (X) and response variable (y) training and test data:</p>
  
  <pre><code>X_train = [(N-1) * 3], y_train = [(N-1) * 40], X_test = [1 * 3], y_test = [1 * 40]
  </code></pre>
  
  <p>As I would expect, such an approach should yield:</p>
  
  <pre><code>y = intercept + a x1 + b x1^2 + c x2 + d x2^2 + e x3 + f x3^3 + g x1 x2 + h x1 x3 + i x2 x3
  </code></pre>
  
  <p>Which is a total of 9 coefficients plus one intercept for every sample to describe the polynomial. If I use the method proposed earlier by David Maust in 2015:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from sklearn.linear_model import LinearRegression
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import PolynomialFeatures
  from sklearn.pipeline import *
  
  model = make_pipeline(PolynomialFeatures(degree=2),LinearRegression())
  y_poly = model.fit(X_train,y_train)
  
  coefficients = model.steps[1][1].coef_
  intercepts = model.steps[1][1].intercept_
  
  coefficients.shape
  
  [Output: (40, 10)]
  </code></pre>
  
  <p>For every response variable, it appears we end up with 10 coefficients + one intercept, which is one more coefficient than I would expect. Therefore it is unclear to me what these coefficients mean and how to make up the polynomial that describes our response variable. I really hope StackOverflow could help me out! Hopefully I defined my problem well enough.</p>