我正在尝试使用scikit learn库计算Cohen的非数值值的kappa。有没有办法将标签数组[“快乐”,“悲伤”,“快乐”]转换为花车?
from skll.metrics import kappa
y_true = ["HAPPINESS","OTHER","NONE","FEAR","NONE","NONE","NONE","ANGER"]
y_pred = ["HAPPINESS","NONE","NONE","FEAR","NONE","NONE","NONE","NONE"]
kappa_val = kappa(y_true, y_pred)
现在我收到此错误:
ValueError: could not convert string to float: "HAPPINESS"
答案 0 :(得分:0)
您需要使用from sklearn import preprocessing
from sklearn.metrics import classification
import numpy as np
y_true = ["HAPPINESS","OTHER","NONE","FEAR","NONE","NONE","NONE","ANGER"]
y_pred = ["HAPPINESS","NONE","NONE","FEAR","NONE","NONE","NONE","NONE"]
enc = preprocessing.LabelEncoder()
enc.fit(np.hstack((y_pred, y_true))) #have to give it all possible labels
kappa_val = classification.cohen_kappa_score(enc.transform(y_true), enc.transform(y_pred))
print kappa_val
0.578947368421
给出输出
android:clickable:true