gpt4 book ai didi

python - GridSearchCV不支持多类吗?

转载 作者:行者123 更新时间:2023-12-02 08:19:12 25 4
gpt4 key购买 nike

我尝试根据此处的答案将 GridSearchCV 用于多类案例:

Accelerating the prediction

但是我得到了值错误,不支持多类格式。

如何在多类情况下使用此方法?

以下代码来自上面链接中的答案。

import numpy as np
from sklearn.datasets import make_classification
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.pipeline import make_pipeline
from sklearn.grid_search import GridSearchCV
from sklearn.metrics import accuracy_score, recall_score, f1_score, roc_auc_score, make_scorer

X, y = make_classification(n_samples=3000, n_features=5, weights=[0.1, 0.9, 0.3])

pipe = make_pipeline(StandardScaler(), SVC(kernel='rbf', class_weight='auto'))

param_space = dict(svc__C=np.logspace(-5,0,5), svc__gamma=np.logspace(-2, 2, 10))

accuracy_score, recall_score, roc_auc_score
my_scorer = make_scorer(roc_auc_score, greater_is_better=True)

gscv = GridSearchCV(pipe, param_space, scoring=my_scorer)
gscv.fit(X, y)

print gscv.best_params_

最佳答案

来自 roc_auc_score 的文档:

Note: this implementation is restricted to the binary classification task or multilabel classification task in label indicator format.

通过“标签指示器格式”,它们意味着每个标签值都表示为二进制列(而不是单个列中的唯一目标值)。您不想对预测器执行此操作,因为它可能会导致非互斥的预测(即,为情况 p1 预测标签 2 和 4,或为情况 p2 预测没有标签)。

选择或自定义实现针对多类问题明确定义的评分函数,例如 F1 score 。我个人发现informedness比 F1 分数更有说服力,比 roc_auc_score 更容易推广到多类问题。

关于python - GridSearchCV不支持多类吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265110/

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