python-3.x - GridSearchCV 不报告详细模式下的分数

标签 python-3.x machine-learning scikit-learn

我正在 python 3.8.5 和 sklearn 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
 |      Controls the verbosity: the higher, the more messages.
 |  
 |      - >1 : the computation time for each fold and parameter candidate is
 |        displayed;
 |      - >2 : the score is also displayed;
 |      - >3 : the fold and candidate parameter indexes are also displayed
 |        together with the starting time of the computation.

设置verbose = 3(我这样做)应该打印每次运行的马修斯相关系数。

但是,输出是

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?

也许这是因为我使用的是非标准记分器?

最佳答案

我在几个不同的 sklearn 版本中尝试了与您的代码类似的内容。事实证明,0.24.1 版在 verbose=3 时不会打印分数。

这是我的代码和 sklearn 版本 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

这是我的 sklearn 版本 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 修复此错误。

关于python-3.x - GridSearchCV 不报告详细模式下的分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67526377/

相关文章:

machine-learning - 如何为棋盘游戏(wizwoz)结果创建评估函数

python - 在 sklearn 中使用 Boosting 树生成特征

python - 用Python检查决策树分类器的准确性

arrays - Matrix/2D-numpy 数组中的着色条目?

python - 初始化多个字符串,并将每个具有多个值的字符串初始化为一个变量。对字符串执行操作

python - Tensorflow 加权交叉熵损失函数在 DNN 分类器估计器函数中的位置在哪里?

machine-learning - RNN 输出层的梯度是否应该被剪裁?

machine-learning - 机器学习模型不适用于连续数据

python - itertools 'previous' (next 的对面) python

python - 如何在碰撞后实现超时/冷却