我正在 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 --upgrade
或 pip install scikit-learn==0.24.2
修复此错误。
关于python-3.x - GridSearchCV 不报告详细模式下的分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67526377/