How to Evaluate a Machine Learning Model: A Complete Beginner’s Guide
On this page
Short answer: To evaluate a machine learning model, (1) split data so the model is tested on examples it hasn’t seen (train/validation/test, or cross-validation; use time-based splits for time series), (2) choose metrics that match the business problem: precision, recall, F1 and ROC-AUC for classification, or MAE and RMSE for regression, (3) compare against a simple baseline, (4) tune the decision threshold to the cost of errors, and (5) check performance across important segments and over time. A model is “good” only if it beats the baseline on the metric that matters to the business.
Key takeaways
- Never judge a model on its training data.
- Accuracy is misleading for imbalanced problems.
- Choose metrics by the cost of mistakes, not by habit.
- Always compare with a baseline (for example, always predicting the average or the majority class).
- Evaluate by segment and monitor after deployment.
Step 1: Split your data correctly
| Split | Purpose |
|---|---|
| Training set | Fit the model |
| Validation set (or cross-validation) | Compare models and tune hyperparameters |
| Test set | Final, unbiased estimate, used once at the end |
- K-fold cross-validation gives a more stable estimate for small datasets
- Stratified splits keep class proportions similar, which matters for imbalanced classification
- Time-based splits train on the past and test on the future, which is essential for forecasting
- Keep related records (for example the same customer) in the same split to avoid leakage
Step 2: Classification metrics
The confusion matrix
| Predicted positive | Predicted negative | |
|---|---|---|
| Actual positive | True positive (TP) | False negative (FN) |
| Actual negative | False positive (FP) | True negative (TN) |
| Metric | Formula (idea) | Use when |
|---|---|---|
| Accuracy | (TP+TN) / all | Classes are balanced and errors cost similarly |
| Precision | TP / (TP+FP) | False alarms are costly |
| Recall | TP / (TP+FN) | Missing positives is costly (fraud, disease) |
| F1-score | Harmonic mean of precision and recall | You need a balance on imbalanced data |
| ROC-AUC | Ranking quality across thresholds | Comparing models’ ability to separate classes |
| PR-AUC | Precision-recall trade-off across thresholds | Positives are rare |
| Log loss | Penalises confident wrong probabilities | Probability quality matters |
from sklearn.metrics import classification_report, roc_auc_score, confusion_matrix
y_pred = model.predict(X_test)
y_proba = model.predict_proba(X_test)[:, 1]
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))
print('ROC-AUC:', roc_auc_score(y_test, y_proba))
Step 3: Regression metrics
| Metric | Meaning | Note |
|---|---|---|
| MAE | Average absolute error | Easy to explain in business units |
| RMSE | Square root of average squared error | Penalises large errors more |
| R² | Share of variance explained | Useful for comparison, but not on its own |
| MAPE | Average percentage error | Intuitive, but unstable when actual values are near zero |
Step 4: Compare against a baseline
Baselines tell you whether the model adds value:
- Classification: always predict the majority class, or use a simple rule
- Regression: predict the mean or median
- Forecasting: “same as last week/month” (naive forecast)
If your model doesn’t clearly beat the baseline, improve features or rethink the approach. See Feature Engineering Explained.
Step 5: Tune the decision threshold
Most classifiers output probabilities; the default 0.5 threshold is rarely optimal. Choose the threshold using the business cost of false positives vs false negatives, or a target such as “catch at least 80% of fraud at the lowest false-alarm rate”.
Step 6: Check overfitting and stability
- A large gap between training and validation scores signals overfitting
- Look at variation across cross-validation folds
- Plot learning curves to see whether more data would help
Step 7: Evaluate by segment and over time
A model can perform well overall but poorly for specific groups (regions, customer types, new users). Check metrics by segment, review fairness where decisions affect people, and monitor performance after deployment because data drifts. See What Is MLOps?
Step 8: Translate metrics into business impact
Decision-makers rarely care about F1 itself. Translate results: “At this threshold, we catch 7 of every 10 likely churners while contacting 20% of customers”, or “Forecast error is about 8% on average, down from 15% with the current method.”
Common evaluation mistakes
- Evaluating on training data, or tuning on the test set
- Random splits for time-series data
- Reporting accuracy on imbalanced data
- Data leakage from preprocessing on the full dataset
- Ignoring the baseline
Frequently asked questions
What is a good accuracy for a machine learning model?
It depends on the problem, the baseline and the cost of errors. A 95% accuracy can be useless if 95% of cases belong to one class.
What is the difference between validation and test sets?
The validation set is used to make modelling decisions; the test set is kept untouched for a final, unbiased estimate.
Should I use ROC-AUC or PR-AUC?
Use PR-AUC when positives are rare and you care mainly about the positive class; ROC-AUC is useful for general ranking comparison.
How do I evaluate LLM or RAG applications?
Use task-specific test sets and measures such as correctness, faithfulness and relevance. See RAG interview questions.
Conclusion
Evaluating a machine learning model means testing on unseen data, choosing metrics that reflect real costs, beating a baseline, tuning thresholds and checking segments over time. Master this, and you’ll build models people can trust, and answer one of the most common machine learning interview questions with confidence.
Learn model evaluation hands-on in our Machine Learning course.
Related reading
Learn with Mehul Prajapati in Borivali West
At Mehul Prajapati’s institute, you get 100% practical, hands-on training by industry experts with a minimum of 5+ years of experience, plus job-oriented programmes with placement support. Weekday and weekend batches are available, with multiple 2-hour slots between 8 am and 6 pm.
Address: 12th Floor, 1214, Gold Crest Business Centre, LT Rd, Above Westside Showroom, Borivali West, Mumbai, Maharashtra 400092
Call: +91 99301 12627 / +91 96645 45072
Visit the centre or call us to choose the right course and batch and to know the current fee structure.