title: Polynomial regression print feature names and intercept of learned function
body: <p>I'm trying to print the function learned by scikit-learn when doing a polynomial regression.</p>
  
  <p>I wrote the following code, based on <a href="http://scikit-learn.org/stable/auto_examples/linear_model/plot_polynomial_interpolation.html" rel="nofollow noreferrer">this example</a> and what I learned from <a href="https://stackoverflow.com/q/31290976/1600770">this question</a>. I got it working, but I'm not sure how to interpret the output.</p>
  
  <p>The intercept should be separate from the coefficients, yet using <code>get_feature_names</code> I get a column named "1", which sounds like the name of the intercept column.</p>
  
  <p>After fitting the model, I get a zero coefficient for that column, but the value of the model intercept is -0.122 (not zero).</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from sklearn.linear_model import Ridge
  from sklearn.preprocessing import PolynomialFeatures
  
  
  # function that we want to learn
  def f(x):
      return x * np.sin(x)
  
  
  # generate points and keep a subset of them
  x = np.linspace(0, 10, 100)
  rng = np.random.RandomState(0)
  rng.shuffle(x)
  x = np.sort(x[:20])
  y = f(x)
  
  # from 1d vector to 2d array, multiple rows with a single column
  X = x[:, np.newaxis]
  
  # add polynomial features to X
  degree = 5
  poly = PolynomialFeatures(degree)
  poly_X = poly.fit_transform(X)
  feature_names = ['x']
  poly_feature_names = poly.get_feature_names(feature_names)
  
  # fit the ridge linear regression model
  clf = Ridge()
  clf.fit(poly_X, y)
  
  # print learned function in readable form
  learned_f = 'learned function:\n'
  intercept = clf.intercept_
  learned_f += '{:+.3f}'.format(intercept)
  coefficients = clf.coef_
  assert(len(coefficients) == len(poly_feature_names))
  assert(coefficients[0] == 0.0)  # the first coefficient is 0
  for i in range(0, len(coefficients)):
      learned_f += ' {:+.3f} {}'.format(coefficients[i], poly_feature_names[i])
  print(learned_f)
  
  # generate points used to plot
  x_plot = np.linspace(0, 10, 100)
  X_plot = x_plot[:, np.newaxis]
  
  # plot function we want to learn
  lw = 2
  plt.plot(x_plot, f(x_plot), color='cornflowerblue',
           linewidth=lw, label='ground truth')
  plt.scatter(x, y, color='navy', s=30, marker='o',
              label='training points')
  
  # plot points predicted by the learned function
  poly_X_plot = poly.transform(X_plot)
  y_plot = clf.predict(poly_X_plot)
  plt.plot(x_plot, y_plot, color='teal', linewidth=lw,
           label='learned poly degree %d' % degree)
  
  # place legend and show plot
  plt.legend(loc='lower left')
  plt.tight_layout()
  plt.show()
  </code></pre>
  
  <p>Output, notice the first two terms <code>-0.122 +0.000 1</code></p>
  
  <pre><code>learned function:
  -0.122 +0.000 1 +1.088 x +1.132 x^2 -0.950 x^3 +0.180 x^4 -0.010 x^5
  </code></pre>
  
  <p>Figure to help see what's going on
  <a href="https://i.stack.imgur.com/RZAoa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RZAoa.png" alt="polynomial regression learning sine function"></a></p>
  
  <p>Is my code correct? If so, how do I interpret the column named "1"?
  Is it a placeholder for the intercept or something else?</p>
  
  <p>Here are my specs</p>
  
  <pre><code>Linux-4.9.0-7-amd64-x86_64-with-debian-9.5
  ('Python', '2.7.13 |Anaconda 4.4.0 (64-bit)| (default, Dec 20 2016, 23:09:15) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]')
  ('NumPy', '1.12.1')
  ('SciPy', '0.19.0')
  ('Scikit-Learn', '0.18.1')
  </code></pre>