Neylora Data & AI Academy

Free Learning Resource

Machine Learning Evaluation Metrics

Choose metrics according to the ML problem and business objective.

Regression Metrics

MetricMeaning
MAEAverage absolute prediction error
MSEAverage squared error; penalizes large errors
RMSESquare root of MSE, in target units
Proportion of target variance explained by the model
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score

mae = mean_absolute_error(y_test, y_pred)
mse = mean_squared_error(y_test, y_pred)
rmse = mse ** 0.5
r2 = r2_score(y_test, y_pred)

Classification Metrics

MetricTypical use
AccuracyOverall correctness
PrecisionFalse positives are costly
RecallFalse negatives are costly
F1 ScoreBalance of precision and recall
ROC-AUCClass discrimination across thresholds
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score

accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)

Confusion Matrix

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
Remember: Select the metric based on the problem, class balance and cost of errors.

← Back to Academy