Signature
accuracy_score(y_true, y_pred, normalize=True)What it does
accuracy_score compares predicted labels with true labels. It is easy to interpret but can hide poor performance on imbalanced classes, where a majority-class baseline may already score highly.
Parameters
y_truearray_like- Ground-truth labels.
y_predarray_like- Predicted labels in the same order.
normalizebool, optionaloptional- Return a fraction when True, a count when False.
Returns
float
Example
pythonaccuracy_score example
from sklearn.metrics import accuracy_score
score = accuracy_score(y_test, predictions)
print(f"accuracy: {score:.3f}")Watch out for
- Accuracy alone is misleading for rare classes; also inspect precision, recall, and a confusion matrix.
- y_true and y_pred must be aligned row by row.