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

Your Y_pred_binarised_train is binarised (as named), but your Y_train is not. Binarise Y_train as well before using the classification metric accuracy_score in code below:

accuracy_train = accuracy_score(Y_pred_binarised_train, Y_train)

Binarising Y_train will, fix the error.

Following comments are based on a quick look and may not be very relevant.

  • I think, you also need to review what you are trying to achieve. For e.g. you can start with printing Y_pred_binarised_train and convince yourself if its ok.

  • Also you can print Y_pred_train and Y_train and analyse the values before binarising them. May be you need a better threshold for binarising or something else.

  • Or, if you are using it as regression (continuous values), you don’t want to binarise at all. In that case, look for some other appropriate metric other than accuracy_score which is for classification.

1 Like

I read some documents and I found my mistake. As I am looking for regression accuracy_score is not the right metric. MSE, MAE and Inlier Ratio Metric are the appropriate metric for regression. I will try to implement the other two.

Sanjay, Thanks a lot for clearing my doubts.

1 Like