随机搜索网格不显示评分指标

Random search grid not displaying scoring metric

我想通过二进制 class 的 XGBClassifier 对一些超参数进行网格搜索,但是每当我 运行 它的分数值 (roc_auc) 都不是展示。我在其他问题中读到这可能与模型训练中的一些错误有关,但我不确定在这种情况下是哪一个。

我的模型训练数据 X_trainnp.array of (X, 19)

我的 y_trainnumpy.ndarray 形状 (X, ) 看起来像这样

然后我以这种方式创建我的模型参数和模型

from sklearn.model_selection import RandomizedSearchCV, GridSearchCV
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import StratifiedKFold
from xgboost import XGBClassifier

# A parameter grid for XGBoost
params = {
        'min_child_weight': [1, 5, 10],
        'gamma': [0.5, 1, 1.5, 2, 5],
        }
xgb = XGBClassifier(use_label_encoder=False, eval_metric='logloss')

folds = 3
param_comb = 5

skf = StratifiedKFold(n_splits=folds, shuffle = True, random_state = 1001)

random_search = RandomizedSearchCV(xgb, 
                                   param_distributions=params,
                                   n_iter=param_comb, 
                                   scoring='roc_auc',
                                   n_jobs=4, 
                                   cv=skf.split(X_train, y_train), 
                                   verbose=3, 
                                   random_state=1001)

random_search.fit(X_train, y_train)

每当我从上面点击代码时,我都会看到这个不包含得分的显示

[CV 3/3] END ..................gamma=0.5, min_child_weight=5; total time= 3.6min
[CV 1/3] END ..................gamma=0.5, min_child_weight=1; total time= 3.7min
[CV 3/3] END .................gamma=0.5, min_child_weight=10; total time= 3.5min
[CV 1/3] END ....................gamma=2, min_child_weight=5; total time= 3.6min
[CV 2/3] END ..................gamma=0.5, min_child_weight=1; total time= 3.5min
[CV 2/3] END .................gamma=0.5, min_child_weight=10; total time= 3.4min
[CV 2/3] END ..................gamma=1.5, min_child_weight=5; total time= 2.5min
[CV 2/3] END ..................gamma=0.5, min_child_weight=5; total time= 3.5min
[CV 2/3] END ....................gamma=2, min_child_weight=5; total time= 3.4min
[CV 3/3] END ..................gamma=0.5, min_child_weight=1; total time= 3.6min
[CV 1/3] END ..................gamma=1.5, min_child_weight=5; total time= 2.5min
[CV 1/3] END ..................gamma=0.5, min_child_weight=5; total time= 3.6min
[CV 3/3] END ....................gamma=2, min_child_weight=5; total time= 3.5min
[CV 1/3] END .................gamma=0.5, min_child_weight=10; total time= 3.4min
[CV 3/3] END ..................gamma=1.5, min_child_weight=5; total time= 2.5min

每次折叠的评估结果在拟合后存储在RandomizedSearchCV实例中。使用 cv_results_ 属性访问它们:

# Access CV validation scores.
print(random_search.cv_results_)

请注意,您还可以通过以下方式访问最佳估算器:

best_estimator = random_search.best_estimator_

RandomizedSearchCV 的文档中有更多内容。