【问题标题】:Invalid Parameter Error in RandomizedSearchCVRandomizedSearchCV 中的无效参数错误
【发布时间】:2021-09-14 19:36:50
【问题描述】:

我正在尝试学习机器学习中的 RandomizedSearchCV。

代码:

data = pd.read_csv("heart-disease.csv")
data_shuffled = data.sample(frac = 1)
X = data_shuffled.drop("target", axis = 1)
y = data_shuffled["target"]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)

grid = {"n_estimators": [10, 100, 200, 500, 1000, 1200],
        "max_depth": [None, 5, 10, 15, 20, 30],
        "max_featuers": ["auto", "sqrt"],
        "min_samples_split": [2, 4, 6],
        "min_samples_leaf": [1, 2, 4]}

rfc = RandomForestClassifier(n_jobs = -1)

rscv = RandomizedSearchCV(estimator = rfc,
                          param_distributions=grid,
                          n_iter = 100,
                          cv = 5,
                          verbose = 1)
rscv.fit(X_train, y_train)

我得到的错误:

ValueError: Invalid parameter max_featuers for estimator RandomForestClassifier(min_samples_leaf=2, min_samples_split=6,
                       n_estimators=1200, n_jobs=-1). Check the list of available parameters with `estimator.get_params().keys()`.

我检查了 RandomForestClassifier 库,看看我是否传递了错误的超参数名称,但我找不到任何东西。

【问题讨论】:

    标签: python machine-learning scikit-learn cross-validation hyperparameters


    【解决方案1】:

    您在参数网格的定义中有错字:它应该是 max_features 而不是 max_featuers

    grid = {
        "n_estimators": [10, 100, 200, 500, 1000, 1200],
        "max_depth": [None, 5, 10, 15, 20, 30],
        "max_features": ["auto", "sqrt"],  # <-- change here
        "min_samples_split": [2, 4, 6],
        "min_samples_leaf": [1, 2, 4]
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多