我正在尝试解决回归问题波士顿数据集 https://www.kaggle.com/c/boston-housing在...的帮助下随机森林回归器 https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html.我正在使用网格搜索简历 https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html用于选择最佳超参数。
问题1
我应该适合吗GridSearchCV
一些X_train, y_train
然后得到最佳参数。
OR
我应该戴上它吗X, y
获得最佳参数。(X,y =整个数据集)
问题2
说如果我适合它X, y
并获得最佳参数,然后在这些最佳参数上建立新模型。
现在我应该如何训练这个新模型?
我应该训练新模型吗X_train, y_train
or X, y.
问题3
如果我训练新模型X,y
那么我将如何验证结果?
到目前为止我的代码
#Dataframes
feature_cols = ['CRIM','ZN','INDUS','NOX','RM','AGE','DIS','TAX','PTRATIO','B','LSTAT']
X = boston_data[feature_cols]
y = boston_data['PRICE']
训练测试数据分割
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 1)
网格搜索以获得最佳超参数
from sklearn.grid_search import GridSearchCV
param_grid = {
'n_estimators': [100, 500, 1000, 1500],
'max_depth' : [4,5,6,7,8,9,10]
}
CV_rfc = GridSearchCV(estimator=RFReg, param_grid=param_grid, cv= 10)
CV_rfc.fit(X_train, y_train)
CV_rfc.best_params_
#{'max_depth': 10, 'n_estimators': 100}
在最大深度:10、n_估计器:100 上训练模型
RFReg = RandomForestRegressor(max_depth = 10, n_estimators = 100, random_state = 1)
RFReg.fit(X_train, y_train)
y_pred = RFReg.predict(X_test)
y_pred_train = RFReg.predict(X_train)
RMSE: 2.8139766730629394
我只是想要一些有关正确步骤的指导