首页 > 解决方案 > 估计器管道的无效参数 rf

问题描述

我将 RandomForestRegressor 与 GridSearchCV 一起使用。我收到此错误:

   ValueError: Invalid parameter RandomForestRegressor for estimator Pipeline

我不明白为什么。这是我的代码:

 pipelines = {
        'rf': make_pipeline(StandardScaler(),
                            RandomForestRegressor(random_state=42)),


rf_hyperparameters = {
    'RandomForestRegressor__n_estimators': [100, 200, 300, 400, 500],
    'RandomForestRegressor__max_features': ['auto', 'sqrt', 0.33]
    }

hyperparameters = {
    'rf': rf_hyperparameters,
}

fitted_alternative_models = {}
for name, pipeline in pipelines.items():
    alt_model = GridSearchCV(pipeline, hyperparameters[name], cv=10, n_jobs=-1)
    alt_model.fit(X_train, y_train.values.ravel())

谢谢!

标签: pythonpipelinerandom-forestgrid-search

解决方案


我变了:

rf_hyperparameters = {
    'RandomForestRegressor__n_estimators': [100, 200, 300, 400, 500],
    'RandomForestRegressor__max_features': ['auto', 'sqrt', 0.33]
    }

至:

rf_hyperparameters = {
     'randomforestregressor__n_estimators': [100, 200, 300, 400, 500],
     'randomforestregressor__max_features': ['auto', 'sqrt', 0.33]
}

它正在工作。


推荐阅读