Open YoungBooker opened 1 year ago
`from sklearn.model_selection import GridSearchCV from sklearn.preprocessing import PolynomialFeatures from sklearn.linear_model import LinearRegression from sklearn.pipeline import make_pipeline import matplotlib.pyplot as plt import numpy as np import seaborn
def PolynomialRegression(degree=2,**kwargs):
return make_pipeline(PolynomialFeatures(degree),
LinearRegression(**kwargs))
def make_data(N,err=1.0,rseed=1):
rng=np.random.RandomState(rseed)
X=rng.rand(N,1)**2
y=10-1./(X.ravel()+0.1)
if err > 0:
y+=err*rng.randn(N)
return X,y
X,y=make_data(40) param_grid = {'polynomialfeaturesdegree': np.arange(21), 'linearregressionfit_intercept': [True, False]}
grid = GridSearchCV(PolynomialRegression(), param_grid, cv=7)
grid.fit(X,y)
print(grid.bestparams)
seaborn.set()
model=grid.bestestimator
plt.scatter(X.ravel(),y)
lim=plt.axis() X_test=np.linspace(-0.1,1.1,500)[:,None]
y_test=model.fit(X,y).predict(X_test) plt.plot(X_test.ravel(),y_test) plt.axis(lim)`
`from sklearn.model_selection import GridSearchCV param_grid = {'polynomialfeaturesdegree': np.arange(21), 'linearregressionfit_intercept': [True, False], 'linearregression__normalize': [True, False]}
grid = GridSearchCV(PolynomialRegression(), param_grid, cv=7) grid.fit(X,y)`
Sorry to bother you. I had a small issue in section 5.3.4 of this book. Jupyter prompts me with the following error。 I also ran the code you gave, but this kind of problem also occurs. (I ran the code for 5.3 through until grid.fit(X,y)) My English is not very good, sorry again.
ValueError: Invalid parameter 'normalize' for estimator LinearRegression(). Valid parameters are: ['copy_X', 'fit_intercept', 'n_jobs', 'positive'].