Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
from sklearn.preprocessing import PolynomialFeatures
X = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
X_poly = PolynomialFeatures(degree=2).fit_transform(X)
print(X_poly.shape[1])6
- Expecting
5: by defaultinclude_bias=Trueadds a column of ones, so the columns are 1, a, b, a², a·b and b². - Expecting
9from counting a·b and b·a apart: they are one product, andPolynomialFeaturesmakes one column for it.
- Which columns disappear with
include_bias=False, and why doesLinearRegressionnot need them? - How does the number of columns grow when a third input feature is added at the same degree?