【问题标题】:F1_score in python codepython代码中的F1_score
【发布时间】:2014-03-20 12:42:26
【问题描述】:

我对 python 中的指标有一些疑问。我有下一个错误: “ValueError:无法处理多类和连续的混合”。

我的代码如下所示(附加参数的全部信息):

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')

我认为,有些参数是错误的,但乍一看一切都很好......无法真正检查,哪里有问题......

【问题讨论】:

  • 请发布完整的回溯。它会准确地告诉您错误发生的位置。

标签: python scikit-learn metrics


【解决方案1】:

这就是问题所在:

y_predict = clf.predict_proba(X_test)[:,1]
print f1_score(y_test,y_predict)

F1 是在标签上定义的,而不是概率分布,所以使用predict 而不是predict_proba

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-22
    • 2016-01-19
    • 2016-02-23
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    相关资源
    最近更新 更多