2015-10-25 76 views
1

計算F1我試圖計算multi-label classificationscikit在多標籤分類

from sklearn.metrics import f1_score 

y_true = [[1,2,3]] 
y_pred = [[1,2,3]] 

print f1_score(y_true, y_pred, average='macro') 

宏觀F1與scikit然而,它失敗,錯誤消息

ValueError: multiclass-multioutput is not supported 

如何計算宏觀F1多標籤分類?

回答

3

在當前scikit學習釋放,你的代碼產生以下警告:

DeprecationWarning: Direct support for sequence of sequences multilabel 
    representation will be unavailable from version 0.17. Use 
    sklearn.preprocessing.MultiLabelBinarizer to convert to a label 
    indicator representation. 

按照這個建議,你可以用sklearn.preprocessing.MultiLabelBinarizer這個多標籤類轉換到由f1_score接受的形式。例如:

from sklearn.preprocessing import MultiLabelBinarizer 
from sklearn.metrics import f1_score 

y_true = [[1,2,3]] 
y_pred = [[1,2,3]] 

m = MultiLabelBinarizer().fit(y_true) 

f1_score(m.transform(y_true), 
     m.transform(y_pred), 
     average='macro') 
# 1.0 
+0

想知道如何實現這個多重回歸問題。 – TheNastyOne