bobo老师,你好
我试图用线性回归模型对波士顿房价数据进行预测,我试了两种方法建立模型,
第一种:
pip_clf = Pipeline([
("scaler", StandardScaler()),
("lin_reg", LinearRegression())
])
#精度为:0.8111288663608667
第二种:
gridsearch = GridSearchCV(pip_clf, param_grid={},cv=5)
#精度为:0.3532759243958822
为什么网格搜索的结果要差这么多呢?网格搜索准确度不是应该高一些吗
完整代码如下:
在这里输入代码
import numpy as np
from sklearn import datasets
from sklearn.linear_model import Ridge
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split
boston = datasets.load_boston()
x = boston.data
y = boston.target
X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=66, test_size = 0.2)
pip_clf = Pipeline([
("scaler", StandardScaler()),
("lin_reg", LinearRegression())
])
#方法一
pip_clf.fit(X_train, y_train)
pip_clf.score(X_test, y_test)
#0.8111288663608667
#方法一
gridsearch = GridSearchCV(pip_clf, param_grid={},cv=5)
gridsearch.fit(x, y)
gridsearch.best_score_
#0.3532759243958822