【发布时间】:2018-12-12 19:35:16
【问题描述】:
我正在尝试使用 RandomizedSearchCV 对 随机森林 进行一些超参数优化。我将评分方法设置为平均精度。 rand_search.best_score_ 大约是 0.38(对于我的数据集来说是一个合理的结果),但是当我使用 rand_search.best_estimator_ 计算相同的平均精度分数时,结果接近 1(见下文)。
clf = RandomForestClassifier()
randsearch = RandomizedSearchCV(clf,
scoring='average_precision',
param_distributions=parameters,
n_iter=1,
cv=StratifiedShuffleSplit(n_splits=10),
n_jobs=1,
verbose=2)
randsearch.fit(X, y)
randomized_best_score = randsearch.best_score_
best_estimator_avg_precision = average_precision_score(y,
randsearch.best_estimator_.predict(X))
best_estimator_avg_precision_probs = average_precision_score(y,
randsearch.best_estimator_.predict_proba(X)[:, 1])
print(randomized_best_score)
print(best_estimator_avg_precision)
print(best_estimator_avg_precision_probs)
>>> randomized_best_score: 0.3836
>>> best_estimator_avg_precision: 0.983577210629
>>> best_estimator_avg_precision_probs: 1.0
知道为什么会发生这种情况吗?我做错了什么?
【问题讨论】:
标签: python scikit-learn random-forest grid-search