1
我可以用下面的方法做的二進制數據的交叉驗證,但似乎不工作的多類數據:如何對多類數據進行交叉驗證?
> cross_validation.cross_val_score(alg, X, y, cv=cv_folds, scoring='roc_auc')
/home/ubuntu/anaconda3/lib/python3.6/site-packages/sklearn/metrics/scorer.py in __call__(self, clf, X, y, sample_weight)
169 y_type = type_of_target(y)
170 if y_type not in ("binary", "multilabel-indicator"):
--> 171 raise ValueError("{0} format is not supported".format(y_type))
172
173 if is_regressor(clf):
ValueError: multiclass format is not supported
> y.head()
0 10
1 6
2 12
3 6
4 10
Name: rank, dtype: int64
> type(y)
pandas.core.series.Series
我也試圖改變roc_auc
到f1
但仍然有錯誤:
/home/ubuntu/anaconda3/lib/python3.6/site-packages/sklearn/metrics/classification.py in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight)
1016 else:
1017 raise ValueError("Target is %s but average='binary'. Please "
-> 1018 "choose another average setting." % y_type)
1019 elif pos_label not in (None, 1):
1020 warnings.warn("Note that pos_label (set to %r) is ignored when "
ValueError: Target is multiclass but average='binary'. Please choose another average setting.
是否有任何方法可以用來對這種類型的數據進行交叉驗證?
ROC只適用於二進制分類器。你應該考慮另一個評分函數,或者用One vs Rest方法來計算你的ROC。 – sjakw
檢查'average'參數[here](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html#sklearn.metrics.f1_score)和[here](http:// scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html#sklearn.metrics.roc_auc_score)並使用適當的一個。 –