GridSearchCV 在详细模式下不报告分数

我在 Python 3.8.5 和 scikit-learn 0.24.1 上运行了一个使用 GridSearchCV 的参数网格:

grid_search = GridSearchCV(estimator=xg_clf, scoring=make_scorer(matthews_corrcoef), param_grid=param_grid, n_jobs=args.n_jobs, verbose = 3)

根据文档,

 |  verbose : int |      控制详细程度:数值越高,输出的信息越多。 |   |      - >1 : 显示每个折叠和参数候选的计算时间; |      - >2 : 也显示分数; |      - >3 : 还显示折叠和候选参数的索引,以及计算的开始时间。

设置 verbose = 3 后,应该会打印每次运行的马修斯相关系数(Matthews Correlation Coefficient)。

然而,输出结果是

Fitting 5 folds for each of 480 candidates, totalling 2400 fits[CV 1/5] END colsample_bytree=0.8, gamma=0, learning_rate=0.7, max_depth=3, n_estimators=200, subsample=0.9; total time=   0.2s[CV 2/5] END colsample_bytree=0.8, gamma=0, learning_rate=0.7, max_depth=3, n_estimators=200, subsample=0.9; total time=   0.2s[CV 3/5] END colsample_bytree=0.8, gamma=0, learning_rate=0.7, max_depth=3, n_estimators=200, subsample=0.9; total time=   0.2s[CV 4/5] END colsample_bytree=0.8, gamma=0, learning_rate=0.7, max_depth=3, n_estimators=200, subsample=0.9; total time=   0.2s[CV 5/5] END colsample_bytree=0.8, gamma=0, learning_rate=0.7, max_depth=3, n_estimators=200, subsample=0.9; total time=   0.2s[CV 1/5] END colsample_bytree=0.8, gamma=0, learning_rate=0.7, max_depth=3, n_estimators=200, subsample=0.95; total time=   0.2s

为什么 GridSearchCV 没有打印每次运行的马修斯相关系数(MCC)?

可能是因为我使用了一个非标准的评分器?


回答:

我尝试了与你的代码类似的几种不同的 scikit-learn 版本。结果发现,版本 0.24.1 在 verbose=3 时不会输出分数。

以下是使用 scikit-learn 版本 0.22.2.post1 的代码和输出:

clf = XGBClassifier()search = GridSearchCV(estimator=clf, scoring=make_scorer(matthews_corrcoef),                      param_grid={'max_depth':[3, 4, 5]}, verbose=3)search.fit(X, y)> Fitting 5 folds for each of 3 candidates, totalling 15 fits  [CV] max_depth=3 .....................................................  [CV] ......................... max_depth=3, score=0.959, total=   0.2s

以下是使用 scikit-learn 版本 0.24.1 的代码和输出:

clf = XGBClassifier()search = GridSearchCV(estimator=clf, scoring=make_scorer(matthews_corrcoef),                      param_grid={'max_depth':[3, 4, 5]}, verbose=3)search.fit(X, y)> Fitting 5 folds for each of 3 candidates, totalling 15 fits  [CV 1/5] END ....................................max_depth=3; total time=   0.2s

总之,你发现了一个错误。通常,我会建议在 GitHub 上开一个问题,但你会高兴地知道,版本 0.24.2 确实会打印每个折叠的分数。

你可以尝试 pip install scikit-learn --upgradepip install scikit-learn==0.24.2 来修复这个错误。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注