gpt4 book ai didi

python - cv_result中的 'mean_test_score'是什么意思?

转载 作者:太空狗 更新时间:2023-10-30 02:16:17 25 4
gpt4 key购买 nike

你好,我正在做一个 GridSearchCV,我正在使用 scikit learn.cv_results_ 函数打印结果。

我的问题是,当我手动评估所有测试分数拆分的平均值时,我得到的数字与 'mean_test_score' 中所写的数字不同。哪个与标准的 np.mean() 不同?

我在这里附上代码和结果:

n_estimators = [100]
max_depth = [3]
learning_rate = [0.1]

param_grid = dict(max_depth=max_depth, n_estimators=n_estimators, learning_rate=learning_rate)

gkf = GroupKFold(n_splits=7)


grid_search = GridSearchCV(model, param_grid, scoring=score_auc, cv=gkf)
grid_result = grid_search.fit(X, Y, groups=patients)

grid_result.cv_results_

这个操作的结果是:

{'mean_fit_time': array([ 8.92773601]),
'mean_score_time': array([ 0.04288721]),
'mean_test_score': array([ 0.83490629]),
'mean_train_score': array([ 0.95167036]),
'param_learning_rate': masked_array(data = [0.1],
mask = [False],
fill_value = ?),
'param_max_depth': masked_array(data = [3],
mask = [False],
fill_value = ?),
'param_n_estimators': masked_array(data = [100],
mask = [False],
fill_value = ?),
'params': ({'learning_rate': 0.1, 'max_depth': 3, 'n_estimators': 100},),
'rank_test_score': array([1]),
'split0_test_score': array([ 0.74821666]),
'split0_train_score': array([ 0.97564995]),
'split1_test_score': array([ 0.80089016]),
'split1_train_score': array([ 0.95361201]),
'split2_test_score': array([ 0.92876979]),
'split2_train_score': array([ 0.93935856]),
'split3_test_score': array([ 0.95540287]),
'split3_train_score': array([ 0.94718634]),
'split4_test_score': array([ 0.89083901]),
'split4_train_score': array([ 0.94787374]),
'split5_test_score': array([ 0.90926355]),
'split5_train_score': array([ 0.94829775]),
'split6_test_score': array([ 0.82520379]),
'split6_train_score': array([ 0.94971417]),
'std_fit_time': array([ 1.79167576]),
'std_score_time': array([ 0.02970254]),
'std_test_score': array([ 0.0809713]),
'std_train_score': array([ 0.0105566])}

如您所见,对所有 test_score 执行 np.mean 得到的值大约为 0.8655122606479532,而“mean_test_score”为 0.83490629

谢谢你的帮助,莱昂纳多。

最佳答案

由于代码太多,我会将其作为新答案发布:

折叠的测试和训练分数是:(取自您在问题中发布的结果)

test_scores = [0.74821666,0.80089016,0.92876979,0.95540287,0.89083901,0.90926355,0.82520379]
train_scores = [0.97564995,0.95361201,0.93935856,0.94718634,0.94787374,0.94829775,0.94971417]

这些折叠中的训练样本数量是:(取自 print([(len(train), len(test)) for train, test in gkf.split(X, groups=patients) 的输出)]))

train_len = [41835, 56229, 56581, 58759, 60893, 60919, 62056]
test_len = [24377, 9983, 9631, 7453, 5319, 5293, 4156]

然后以每折的训练样本量为权重的测试和训练均值是:

train_avg = np.average(train_scores, weights=train_len)
-> 0.95064898361714389
test_avg = np.average(test_scores, weights=test_len)
-> 0.83490628649308296

所以这正是 sklearn 给你的值(value)。它也是分类的正确平均准确度。折叠的平均值是不正确的,因为它取决于您选择的有点随意的拆分/折叠。

所以在脑震荡中,这两种解释确实是相同和正确的。

关于python - cv_result中的 'mean_test_score'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44947574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com