我正在使用 RandomForestRegressor 生成新功能:
旧脚本需要 20 分钟才能完成,但仍然完成......
**param_grid = {
'n_estimators': [10, 50, 100, 1000],
'max_depth' : [4,5,6,7,8],
}
def rfr_model(X, Y):
--执行网格搜索
gsc = GridSearchCV(
estimator=RandomForestRegressor(),
param_grid=param_grid,
cv=5, scoring='neg_mean_squared_error', verbose=0, n_jobs=-1)
grid_result = gsc.fit(X, Y)
best_params = grid_result.best_params_
rfr = RandomForestRegressor(max_depth=best_params["max_depth"], n_estimators=best_params["n_estimators"],
random_state=False, verbose=False)
--执行K-Fold CV
MSE = cross_val_score(rfr, X, Y, cv=5, scoring='neg_mean_squared_error')
return MSE
但是现在我也想显示我的预测值,所以我添加了 cross_val_predict 并且模型永远不会完成:
# Perform K-Fold CV
MAE = cross_val_score(rfr, X, Y, cv=5, scoring='neg_mean_absolute_error')
MSE = cross_val_score(rfr, X, Y, cv=5, scoring='neg_mean_squared_error')
prediction = cross_val_predict(rfr, X, Y, cv=5)
return print("MAE: ",MAE), print("MSE: ",MSE), prediction
两者都运行:
**X2=pd.concat([x_test,x_train])
Y2=pd.concat([y_test,y_train])
X2 = X2.astype('float64')
Y2 = Y2.astype('float64').values.ravel()**
知道如何解决这个问题吗?
Ps:我是初学者,所以请放轻松。