【问题标题】:Sklearn - Best estimator from GridSearchCV with refit = TrueSklearn - 来自 GridSearchCV 的最佳估计器,refit = True
【发布时间】:2022-07-19 19:28:47
【问题描述】:

我正在尝试使用 GridSearchCV 找到最佳估算器,并且默认情况下我使用 refit = True。鉴于文档指出:

The refitted estimator is made available at the best_estimator_ attribute and permits using predict directly on this GridSearchCV instance

我应该像这样在训练数据上做.fit吗:

            classifier = GridSearchCV(estimator=model,param_grid = parameter_grid['param_grid'], scoring='balanced_accuracy', cv = 5, verbose=3, n_jobs=4,return_train_score=True, refit=True)

            classifier.fit(x_training, y_train_encoded_local)

            predictions = classifier.predict(x_testing)

            balanced_error = balanced_accuracy_score(y_true=y_test_encoded_local,y_pred=predictions)

或者我应该这样做:

            classifier = GridSearchCV(estimator=model,param_grid = parameter_grid['param_grid'], scoring='balanced_accuracy', cv = 5, verbose=3, n_jobs=4,return_train_score=True, refit=True)

            predictions = classifier.predict(x_testing)

            balanced_error = balanced_accuracy_score(y_true=y_test_encoded_local,y_pred=predictions)

【问题讨论】:

    标签: python scikit-learn


    【解决方案1】:

    你应该像你的第一个版本一样,拥有classifier.fitRefit=True 在交叉验证后对整个训练集进行训练。

    【讨论】:

      猜你喜欢
      • 2021-05-12
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      • 2017-05-19
      • 1970-01-01
      • 2019-04-01
      • 2022-09-28
      相关资源
      最近更新 更多