Free Learning Resource
Choose metrics according to the ML problem and business objective.
| Metric | Meaning |
|---|---|
| MAE | Average absolute prediction error |
| MSE | Average squared error; penalizes large errors |
| RMSE | Square root of MSE, in target units |
| R² | 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)
| Metric | Typical use |
|---|---|
| Accuracy | Overall correctness |
| Precision | False positives are costly |
| Recall | False negatives are costly |
| F1 Score | Balance of precision and recall |
| ROC-AUC | Class 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)
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)