【发布时间】:2015-09-24 17:41:09
【问题描述】:
根据此处的答案,我尝试将 GridSearchCV 用于多类案例:
但我得到了值错误,multiclass format is not supported.
如何在多类案例中使用这种方法?
以下代码来自上述链接中的答案。
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_
【问题讨论】:
-
必须发布您的代码。如果我们不知道您在做什么,我们无能为力。
标签: python scikit-learn