title: Scikit learn order of coefficients for multiple linear regression and polynomial features
body: <p>I'm fitting a simple polynomial regression model, and I want get the coefficients from the fitted model.</p>
  
  <p>Given the prep code:</p>
  
  <pre><code>import pandas as pd
  from itertools import product
  from sklearn.linear_model import LinearRegression
  from sklearn.preprocessing import PolynomialFeatures
  from sklearn.pipeline import make_pipeline
  
  # data creation
  sa = [1, 0, 1, 2, 3]
  sb = [2, 1, 0, 1, 2]
  raw = {'a': [], 'b': [], 'w': []}
  for (ai, av), (bi, bv) in product(enumerate(sa), enumerate(sb)):
      raw['a'].append(ai)
      raw['b'].append(bi)
      raw['w'].append(av + bv)
  data = pd.DataFrame(raw)
  
  # regression
  x = data[['a', 'b']].values
  y = data['w']
  poly = PolynomialFeatures(2)
  linr = LinearRegression()
  model = make_pipeline(poly, linr)
  model.fit(x, y)
  </code></pre>
  
  <p>From <a href="https://stackoverflow.com/questions/34373606/scikit-learn-coefficients-polynomialfeatures">this answer</a>, I know the coefficients can obtained using with</p>
  
  <pre><code>model.steps[1][1].coef_
  &gt;&gt;&gt; array([  0.00000000e+00,  -5.42857143e-01,  -1.71428571e+00,
               2.85714286e-01,   1.72774835e-16,   4.28571429e-01])
  </code></pre>
  
  <p>But this provides a 1-dimensional array and I'm not sure which numbers correspond to which variables.</p>
  
  <p>Are they ordered as <strong>a<sup>0</sup>, a<sup>1</sup>, a<sup>2</sup>, b<sup>0</sup>, b<sup>1</sup>, b<sup>2</sup></strong> or as <strong>a<sup>0</sup>, b<sup>0</sup>, a<sup>1</sup>, b<sup>1</sup>, a<sup>2</sup>, b<sup>2</sup></strong>?</p>