准确性得分ValueError:无法处理二进制目标和连续目标的混合 [英] Accuracy Score ValueError: Can't Handle mix of binary and continuous target
问题描述
我正在使用scikit-learn中的linear_model.LinearRegression
作为预测模型.它有效且完美.我在使用accuracy_score
指标评估预测结果时遇到问题.
I'm using linear_model.LinearRegression
from scikit-learn as a predictive model. It works and it's perfect. I have a problem to evaluate the predicted results using the accuracy_score
metric.
这是我的真实数据:
array([1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0])
我的预测数据:
array([ 0.07094605, 0.1994941 , 0.19270157, 0.13379635, 0.04654469,
0.09212494, 0.19952108, 0.12884365, 0.15685076, -0.01274453,
0.32167554, 0.32167554, -0.10023553, 0.09819648, -0.06755516,
0.25390082, 0.17248324])
我的代码:
accuracy_score(y_true, y_pred, normalize=False)
错误消息:
ValueError:无法处理二进制目标和连续目标的混合情况
ValueError: Can't handle mix of binary and continuous target
帮助吗?谢谢.
推荐答案
编辑(后注释):以下内容将解决编码问题,但强烈建议不要使用此方法,因为线性回归模型的分类效果很差,很可能无法正确地分类.
EDIT (after comment): the below will solve the coding issue, but is highly not recommended to use this approach because a linear regression model is a very poor classifier, which will very likely not separate the classes correctly.
阅读下面@desertnaut精心编写的答案,解释为什么此错误暗示着机器学习方法中的某些错误,而不是您必须修复"的某些错误.
Read the well written answer below by @desertnaut, explaining why this error is an hint of something wrong in the machine learning approach rather than something you have to 'fix'.
accuracy_score(y_true, y_pred.round(), normalize=False)
这篇关于准确性得分ValueError:无法处理二进制目标和连续目标的混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!