So, we have our model and it's making predictions, but how do we know if it's any good? To measure the classification performance of our model, we use metrics. There are numerous metrics available, such as accuracy, precision, recall, F1-score, but for this lesson, we will use accuracy score.
Accuracy score is a commonly used metric that gives us the proportion of correct classifications our model made. For example, if our model correctly classified 84 out of 100 messages, the accuracy score is 0.84. The accuracy score can be calculated using accuracy_score from sklearn.metrics.
from sklearn.metrics import accuracy_score
print("Accuracy:", accuracy_score(y_test, y_pred))
The output will be:
Accuracy: 0.964824120603015
This indicates that our logistic regression model was able to correctly classify approximately 96.48% of the messages in the test set, which is a strong result, demonstrating the effectiveness of logistic regression for text classification tasks.
However, keep in mind that "accuracy" might not always be the best metric to evaluate performance, especially for imbalanced datasets where one class far outnumber the others. In such case, evaluation metrics like precision, recall, or F1-score can be more informative.