我对python中的度量有一些疑问。我有下一个错误:"ValueError: Can't handling mix of multiclass and continuous".
我的代码看起来像这样(在参数上添加了整个信息):
X_train,X_test,y_train,y_test = cross_validation.train_test_split(data, target, test_size=0.3, random_state=42)
clf = RFC()
clf = clf.fit(X_train,y_train)
y_predict = clf.predict_proba(X_test)[:,1]
print f1_score(y_test,y_predict)
>>>X_train.shape
(7000, 576)
>>>X_test.shape
(3000, 576)
>>>y_train.shape
(7000,)
>>>y_test.shape
(3000,)
>>>X_train.dtype
dtype('float64')
>>>X_test.dtype
dtype('float64')
>>>y_train.dtype
dtype('float64')
>>>y_test.dtype
dtype('float64')
>>>y_predict.shape
(3000,)
>>>y_predict.dtype
dtype('float64')
我认为,一些参数是错误的,但乍一看一切都很好…
这就是问题所在:
y_predict = clf.predict_proba(X_test)[:,1]
print f1_score(y_test,y_predict)
F1是在标签上定义的,而不是在概率分布上定义的,所以用predict
代替predict_proba
。