Python RandomforestRegressionor-K倍CV交叉值预测永远不会完成

Python RandomforestRegressionor-K倍CV交叉值预测永远不会完成,python,random-forest,cross-validation,k-fold,Python,Random Forest,Cross Validation,K Fold,我正在使用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_g

我正在使用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折叠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:我是初学者,所以请对我放松点