Classification metrics can't handle a mix of binary and continuous targets

前端 未结 2 660
小鲜肉
小鲜肉 2021-02-09 11:51

I try to train and test several scikit-learn models and attempt to print off the accuracy. Only some of these models work, others fail with the

ValueError: Classi         


        
2条回答
  •  爱一瞬间的悲伤
    2021-02-09 12:34

    All your commented-out models are not classifiers but regression models, for which accuracy is meaningless.

    You get the error because these regression models do not produce binary outcomes, but continuous (float) numbers (as all regression models do); so, when scikit-learn attempts to calculate the accuracy by comparing a binary number (true label) with a float (predicted value), it not unexpectedly gives an error. And this cause is clearly hinted at the error message itself:

    Classification metrics can't handle a mix of binary and continuous target
    

    Notice also that the accepted (and highly upvoted...!) answer in the question suggested at the first comment as a possible duplicate of yours is wrong; there, as here, the root cause is the use of accuracy in a LinearRegression model, which, as already said, is meaningless.

提交回复
热议问题