I have worked on a Polynomial Regression model to predict my target values. The thing is that my prediction , with the “predict” method, make sense, but when I calculate the target variable via the coefs and intercept I get a value way far from the given values of the predict method.
pol = PolynomialFeatures(degree= 9) xp = pol.fit_transform(x_train) poly_reg = LinearRegression() poly_reg.fit(xp,y_train) poly_test = pol.fit_transform(x_test) pred = poly_reg.predict(poly_test) poly_reg.predict(pol.fit_transform([[2]])) Output: array([[6.07673981]])
If I calculate the y value for x = 2 via the coefs and intercept, I obtain a value around 90.
[[ 0.00000000e+00, 4.66507179e+00, -7.69101941e-01 ,-5.47401755e-01, 2.92321976e-01, -5.57600284e-02, 5.44143396e-03, -2.91464609e-04, 8.16565621e-06, -9.36811416e-08]][[0.99640058]]
Advertisement
Answer
In Polynomial Transform The value of the variable gets converted in such a way that it fits the linear model.so if the equation is
x^3+x^2+x+c this is the polynomial equation
When you apply polynomial Features it creates values of X such that we can use it in a linear equation so that we can apply the linear model.
So using the linear coefficients with the actual polynomial value of x is going to give a different answer