Sklearn - Best estimator from GridSearchCV with refit = True



我试图使用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)

您应该像第一个版本那样做。你需要一直调用classifier.fit,否则它不会做任何事情。Refit=True表示交叉验证完成后对整个训练集进行训练。

相关内容

  • 没有找到相关文章

最新更新