I have a training set of data x_train
with 6 features/variables and with target y_train
. These are stored in pandas
dataframes.
I have done Linear Regression on this to get a model of the form y = b + m_1*x_1 + m_2*x_2 + ... + m_6*x_6
. When I print LinearRegression().coef_
, I get a numpy array that looks like this: [[m_1, m_2, m_3, m_4, m_5, m_6]]
. From this, I am able to extract the coefficients mi
just fine.
Now I am trying to do Quadratic Regression on this data instead. I expect this to give me a model of the form y = b + m_{11}*x_1 + m_{12}*x_1^2 + m_{21}*x_2 + m_{22}*x_2^2 + ... + m_{62}*x_6^2
. So I expect that I should get 12 coefficients, m_11, m_12, m_21, m_22, m_31, m_32, m_41, m_42, m_51, m_52, m_61, m_62
. Instead, when I print qm.coef_
as shown in the code below, I get a numpy array of length 28:
>>> print(qm.coef_)
[ 5.23243620e-08 -4.52818442e+01 -1.69803868e-02 1.23876223e+00
-1.31251424e+01 6.34950041e+01 -5.65064601e-02 -3.04164916e+00
1.22800976e-03 -1.81908736e-02 -1.38319879e+00 -1.88468027e+00
8.98960781e-03 -5.10163574e-07 5.60756672e-04 -8.52068126e-04
-5.09033748e-03 2.67482109e-06 1.10815787e-01 -7.45059709e-01
-1.05108447e+00 6.37628573e-05 -9.12589844e-01 -1.22173903e+00
-5.47228030e-04 6.34950042e+01 -5.39225901e-03 2.21487661e-06]
My question is, why do I get 28? Where are the 12 that I am looking for, and what are the other 16 coefficients?
Here is my code:
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(x_train)
poly.fit(X_poly, y_train)
qm = LinearRegression()
qm.fit(X_poly, y_train)
print(qm.coef_)
A similar question which was unanswered. Another similar question which wasn't answered correctly.