Cannot get the accuracy of a model through sklearn.metrics

Viewed 16
from sklearn.metrics import accuracy_score
print("Accuracy of the model: {0}%".format(accuracy_score(y_test, y_pred)*100))
NameError                                 Traceback (most recent call last)
Input In [1], in <cell line: 2>()
      1 from sklearn.metrics import accuracy_score
----> 2 print("Accuracy of the model: {0}%".format(accuracy_score(y_test, y_pred)*100))

NameError: name 'y_test' is not defined
1 Answers

The error message suggests that you dont have a variable named y_test. If you are using that code in a new file, make sure to import y_test. If you are using this use in a new cell, make sure the cell that defines y_test was executed before.

Related