-1

I know about the model = LinearRegression() print(model.score(x_test, y_test) method works just fine but I was thinking of a way to use the accuracy_score on LinearRegression and the error I'm getting is bugging me so here I go:

So, I have a data on which I've used the OrdinalEncoding i.e. my y comprises of whole numbers from 1 to 6 and what I thought of was to round the y_pred (after testing on x_test) into nearest whole numbers, converting the entire array to integers and then use accuracy_score on these two different arrays but the following error crops up, can someone please explain me why?

from sklearn.linear_model import LinearRegression
from sklearn.metrics import accuracy_score
model = LinearRegression()
model.fit(x_train, y_train)

y_pred = model.predict(x_test)
y_pred = np.round(y_pred)
y_pred = y_pred.astype(int)
y_test = np.array(y_test)
print(accuracy_score(y_pred, y_test))

gives me:

ValueError: Classification metrics can't handle a mix of multiclass and unknown targets
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • As the answer below says; see also https://stackoverflow.com/questions/38015181/accuracy-score-valueerror-cant-handle-mix-of-binary-and-continuous-target/54458777#54458777 – desertnaut Oct 19 '21 at 19:03
  • Could you rewrite your problem? Example: what you are attempting to do? What is expected results – Prayson W. Daniel Oct 20 '21 at 08:08

1 Answers1

2

we can't use accuracy_score for regression algorithms

in regression problem output is a continuous variable so you can't use accuracy_score for regression problem