Continuous variable not supported in confusion matrix
The confusion matrix is used to tell you how many predictions were classified correctly or incorrectly. You are looking at a regression model, which gives you a continous output (not classification).

So when you run confusion_matrix(y_test, y_pred) it will throw the ValueError because it expected class predictions, not floating point numbers.

Are you trying to predict classes, or really just a number output? If not, then you should not be using the confusion matrix.



If you want to predict e.g. 1 or 0 for your y values, then you would have to convert your linear regression predictions to either of these classes. You could say any value in y_pred above 0.7 is a 1 and anything below is 0.

cutoff = 0.7                              # decide on a cutoff limit
y_pred_classes = np.zeros_like(y_pred)    # initialise a matrix full with zeros
y_pred_classes[y_pred &gt; cutoff] = 1       # add a 1 if the cutoff was breached


you have to do the same for the actual values too:

y_test_classes = np.zeros_like(y_pred)
y_test_classes[y_test &gt; cutoff] = 1


Now run the confusion matrix as before:

confusion_matrix(y_test_classes, y_pred_classes)


which gives output:

array([[2, 3],
       [0, 0]])