I did a code to predict Y values, X and Y are arrays of the same lenght
from sklearn.linear_model import Ridge
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
plt.scatter(X,Y,1)
regr2 = make_pipeline(PolynomialFeatures(10), Ridge())
regr2 =regr2.fit(X[:,np.newaxis], Y)
y_pred=regr2.predict(X[:,np.newaxis])
plt.plot(X, y_pred, color='red')
plt.show()
It works and it is a good approximation But when I do it with test values and train values it shows an exponential when I plot it which it is not supposed to do.
In fact the y_pred1 is the X_test plus a small decimal number
plt.scatter(X_test,Y_test,1)
X_train=X[0:int(0.8*len(X))]
X_test=X[int(0.8*len(X)):]
Y_train=Y[0:int(0.8*len(X))]
Y_test=Y[int(0.8*len(X)):]
regr3 = make_pipeline(PolynomialFeatures(10), Ridge())
regr3 =regr3.fit(X_train[:,np.newaxis], Y_train)
y_pred1=regr3.predict(X_test[:,np.newaxis])
plt.plot(X_test, y_pred1, color='red')
plt.show()
I tried several things, even testing the prediction with the train values and in this case too it plot an exponential instead of an approximation of the points.
Thank in advance!