title: Fitting a higher degree function using PolynomialFeatures and LinearRegression
body: <p>In a book I have found the following code which fits a LinearRegression to quadratic data:</p>
  
  <pre><code>m = 100
  X = 6 * np.random.rand(m, 1) - 3
  y = 0.5 * X**2 + X + 2 + np.random.randn(m, 1)
  poly_features = PolynomialFeatures(degree=2, include_bias=False)
  X_poly = poly_features.fit_transform(X)
  lin_reg = LinearRegression()
  lin_reg.fit(X_poly, y)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Xpzm3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xpzm3.png" alt="enter image description here"></a></p>
  
  <p>But how could that be? I know from the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html" rel="nofollow noreferrer">documentation</a> that <code>PolynomialFeatures(degree=2, include_bias=False)</code> is creating an array which looks like:</p>
  
  <pre><code>[[X[0],X[0]**2]
  [X[1],X[1]**2]
  .....
  [X[n],X[n]**2]]
  </code></pre>
  
  <p>BUT: How is the LinearRegression able to fit this data? Means WHAT is the LinearRegression doing and what is the concept behind this.</p>
  
  <p>I am grateful for any explanations!</p>