Performance Metrics in Machine Learning Explained
You trained a model. Your notebook says 96 percent accuracy. You push it to production, and within a week the engineering team is pinging you on Slack: "Your model is taking 800 milliseconds per prediction and we need it under 100. Also, the infra cost is 4x what we budgeted." Welcome to the part of machine learning that most courses skip entirely.
Performance metrics in machine learning fall into two completely different families, and mixing them up or ignoring one of them is the fastest way to build something that works in a notebook and fails in production. The first family measures prediction quality: how correct your model is. Accuracy, precision, recall, F1, RMSE, R-squared. These are the metrics you learn in every course and tutorial. The second family measures runtime behavior: how fast and how cheaply your model serves predictions. Latency, throughput, model size, cost per inference. These are the metrics that determine whether your model actually ships.
This page is a quick reference for both families. Every metric is a card: the formula, a one-line meaning, when to use it, and the trap that catches people in interviews and production reviews. If you want full walkthroughs with worked examples and the reasoning behind each metric, the evaluation metrics in machine learning guide is the deep-dive companion. This page is the cheat sheet you keep open during a project and review before an interview.
Model Performance: Two Kinds of "Fast and Good"
Most ML courses teach one family of performance metrics: the ones that measure prediction quality. Accuracy, precision, recall, F1, RMSE, R-squared. These answer the question "how correct is my model?"
There is a second family that almost no course covers: runtime performance metrics. Inference latency, throughput, model size, cost per prediction. These answer the question "can my model actually run in production?"
Both families matter. A model with 97 percent accuracy that takes 800 milliseconds per prediction is the wrong choice for a real-time fraud system that needs sub-100ms responses. A model with 93 percent accuracy that responds in 15 milliseconds is the one that ships. This page covers both families because production teams track both, and interviews at product companies increasingly ask about the second family to separate candidates who have only built notebooks from candidates who understand deployed ML.
Stop learning AI in fragments—master a structured AI Engineering Course with hands-on GenAI systems with IIT Roorkee CEC Certification
:::
Classification Metric Cards
The confusion matrix is the foundation for every classification metric below. If you need a refresher on how true positives, false positives, true negatives, and false negatives map out, the confusion matrix guide covers it with visual examples.
Accuracy
| Formula | (TP + TN) / (TP + TN + FP + FN) |
|---|---|
| One-line meaning | Percentage of all predictions that were correct |
| Use when | Classes are balanced and all errors cost roughly the same |
| Trap | 99 percent accuracy on a dataset with 99 percent negatives means your model just predicted "negative" every time. Accuracy is misleading on imbalanced data. |
| scikit-learn | accuracy_score |
Precision
| Formula | TP / (TP + FP) |
|---|---|
| One-line meaning | Of all predictions the model labeled positive, how many actually were positive |
| Use when | False positives are costly (flagging a legitimate email as spam, diagnosing a healthy patient as sick) |
| Trap | A model that predicts "positive" only once and gets it right has 100 percent precision and zero recall. Precision alone is gameable. |
| scikit-learn | precision_score |
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Recall (Sensitivity)
| Formula | TP / (TP + FN) |
|---|---|
| One-line meaning | Of all actual positives, how many did the model find |
| Use when | Missing a positive is costly (cancer detection, fraud detection, defect detection) |
| Trap | A model that predicts "positive" for everything has 100 percent recall and terrible precision. Recall alone is gameable too. |
| scikit-learn | recall_score |
F1 Score
| Formula | 2 × (Precision × Recall) / (Precision + Recall) |
|---|---|
| One-line meaning | Harmonic mean of precision and recall; punishes extreme imbalance between them |
| Use when | You need a single number that balances precision and recall on imbalanced data |
| Trap | F1 treats precision and recall as equally important. If one matters more, use F-beta (F2 weights recall higher, F0.5 weights precision higher). |
| scikit-learn | f1_score |
Specificity
| Formula | TN / (TN + FP) |
|---|---|
| One-line meaning | Of all actual negatives, how many did the model correctly reject |
| Use when | You need to measure how well the model avoids false alarms on the negative class |
| Trap | Rarely reported alone. Most useful alongside sensitivity in medical diagnostics where both classes matter. |
ROC-AUC
| Formula | Area under the Receiver Operating Characteristic curve (TPR vs FPR at all thresholds) |
|---|---|
| One-line meaning | Probability that the model ranks a random positive higher than a random negative |
| Use when | You want a threshold-independent measure of model quality, especially for comparing models |
| Trap | AUC looks at all thresholds, including ones you would never use in practice. Two models can have the same AUC but very different performance at your chosen operating threshold. Also, on highly imbalanced data, Precision-Recall AUC is more informative (Saito & Rehmsmeier, 2015). |
| scikit-learn | roc_auc_score |
Log Loss (Cross-Entropy Loss)
| Formula | −1/N × Σ [yᵢ log(pᵢ) + (1 − yᵢ) log(1 − pᵢ)] |
|---|---|
| One-line meaning | Penalizes confident wrong predictions heavily; lower is better |
| Use when | You care about the quality of predicted probabilities, not just the final class labels |
| Trap | A single very confident wrong prediction (predicting 0.99 for a negative that was actually positive) can dominate the score. This is a feature, not a bug, but it makes log loss sensitive to calibration. |
| scikit-learn | log_loss |
Regression Metric Cards
MAE (Mean Absolute Error)
| Formula | (1/N) × Σ |yᵢ − ŷᵢ| | | :---- | :---- | | One-line meaning | Average absolute difference between predicted and actual values | | Use when | You want an interpretable error metric in the same units as your target variable | | Trap | MAE treats all errors linearly. A prediction that is off by 100 contributes the same as ten predictions off by 10. If large errors are disproportionately bad, use RMSE. | | scikit-learn | mean_absolute_error |
MSE (Mean Squared Error)
| Formula | (1/N) × Σ (yᵢ − ŷᵢ)² |
|---|---|
| One-line meaning | Average of squared differences between predicted and actual values |
| Use when | You want to penalize large errors more heavily than small ones |
| Trap | Squared errors are in squared units, making MSE hard to interpret directly. Report RMSE alongside it for interpretability. |
| scikit-learn | mean_squared_error |
RMSE (Root Mean Squared Error)
| Formula | √MSE |
|---|---|
| One-line meaning | Same as MSE but back in the original units of the target variable |
| Use when | You want the large-error sensitivity of MSE with the interpretability of MAE |
| Trap | Still more sensitive to outliers than MAE. If your data has genuine extreme values, report both RMSE and MAE and explain the gap. |
| scikit-learn | root_mean_squared_error |
R² (Coefficient of Determination)
| Formula | 1 − (SS_residual / SS_total) |
|---|---|
| One-line meaning | Proportion of variance in the target that the model explains |
| Use when | You want a normalized score (0 to 1) to compare models across different datasets |
| Trap | R² can be negative if your model performs worse than simply predicting the mean. It also always increases when you add features, even useless ones. Use Adjusted R² for multi-feature models. |
| scikit-learn | r2_score |
Adjusted R²
| Formula | 1 − [(1 − R²) × (n − 1) / (n − p − 1)] where n = samples, p = features |
|---|---|
| One-line meaning | R² penalized for the number of predictors; only increases if a new feature genuinely improves the model |
| Use when | Comparing models with different numbers of features |
| Trap | Still assumes a linear relationship framework. Not meaningful for non-linear models like random forests or neural networks. |
MAPE (Mean Absolute Percentage Error)
| Formula | (100%/N) × Σ |(yᵢ − ŷᵢ) / yᵢ| | | :---- | :---- | | One-line meaning | Average percentage error relative to actual values | | Use when | You want to communicate error in percentage terms to non-technical stakeholders | | Trap | Undefined when actual values are zero. Asymmetric: overpredicting and underpredicting by the same amount give different MAPE values. Consider SMAPE or MASE as alternatives (Hyndman & Koehler, 2006). |
Measuring Reliably: Validation Reminders
The best metric computed on the wrong split is worse than a mediocre metric computed correctly. Three rules:
- Never evaluate on training data. Always hold out a test set that the model has never seen during training or hyperparameter tuning.
- Use k-fold cross-validation for small datasets where a single train-test split is unreliable. The k-fold cross-validation guide covers the implementation and the common mistake of leaking information between folds.
- Use stratified splits for classification with imbalanced classes to ensure each fold preserves the class distribution.
- scikit-learn provides every metric above as a one-liner. The classification_report function gives precision, recall, and F1 for all classes in a single call. The cross_val_score function handles k-fold evaluation with any scorer.
Build metric evaluation into your workflow from day one: Scaler's free Supervised Learning course covers classification and regression metrics with hands-on exercises using real datasets.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
The Production Layer: Latency, Throughput, and Size
This is the section that separates notebook practitioners from production engineers. Once a model is deployed, teams track metrics that have nothing to do with prediction quality but everything to do with whether the system can serve real users at real scale.
Inference Latency (P50, P95, P99)
What it measures: How long a single prediction takes, from request received to response sent.
Why percentiles matter: A P50 latency of 25ms sounds good. But if P99 is 2,400ms, one in a hundred users is waiting over two seconds. Production teams set SLOs (Service Level Objectives) on P95 or P99, not on averages.
Reference benchmarks for context:
- Real-time user-facing systems (search ranking, recommendation, fraud): P95 target of 50–100ms is standard for web applications. Google's published research on user-facing latency shows that delays above 100ms begin to measurably impact user engagement (Google, "Speed Matters," 2009; Aberdeen Group research found that a 1-second delay in page load time reduces conversions by 7 percent).
- Batch scoring (offline predictions, nightly jobs): Seconds to minutes per prediction are acceptable.
- Edge and mobile inference: Sub-30ms for real-time applications like on-device speech recognition.
What drives latency: Model size, input preprocessing complexity, feature computation at serving time, network overhead between the application and the model server, and hardware (CPU vs GPU vs TPU).
Throughput (Queries Per Second)
What it measures: How many predictions the system can serve per second.
Why it matters: A model that takes 10ms per prediction on a single thread serves 100 QPS. If your application receives 5,000 requests per second at peak, you need horizontal scaling (more instances) or a faster model.
Reference context: Typical production ML serving infrastructure targets 1,000–10,000 QPS per instance for lightweight models (logistic regression, small decision trees) and 100–500 QPS for deep learning models on GPU, depending on model size and input complexity. TensorFlow Serving and TorchServe both publish benchmark suites for their respective frameworks (TensorFlow Serving benchmarks; TorchServe benchmarks).
Model Size and Memory Footprint
What it measures: The disk size of the serialized model and the RAM required to load and run it.
Why it matters: A 2GB model requires expensive GPU instances to serve. A 50MB model runs on CPU and fits on mobile devices. Model size directly determines infrastructure cost.
Reference context:
- scikit-learn models (logistic regression, random forests): typically 1–100MB serialized
- Small deep learning models (distilled BERT, MobileNet): 50–200MB
- Large language models (GPT-2, Llama 7B): 500MB to 14GB+
- Quantized models (INT8 instead of FP32): roughly 4x size reduction with 1–3 percent accuracy loss, as documented in Jacob et al., "Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference" (CVPR 2018)
Cost Per Prediction
What it measures: The infrastructure cost of serving one prediction, combining compute time, memory, and any API costs.
Why it matters: At 10 million predictions per day, the difference between ₹0.001 and ₹0.01 per prediction is ₹90,000 per day. Production teams track this because model serving is an ongoing operational cost, not a one-time training expense.
The Accuracy-Latency Trade-Off (and Monitoring Over Time)
Here is the decision production teams make that courses never discuss: should we sacrifice accuracy to gain latency?
The answer, in most deployed systems, is yes. Here is why.
A BERT-large model might give you 97 percent accuracy on text classification but take 400ms per prediction. Distilling it into a DistilBERT model brings accuracy to 95.5 percent and latency down to 90ms. For a real-time content moderation system serving millions of requests, that 1.5 percent accuracy drop is worth the 4.4x speed improvement because the user experience degradation from 400ms latency costs more than the 1.5 percent additional misclassification rate.
The standard techniques for this trade-off are:
- Knowledge distillation: Train a smaller model to mimic a larger model's outputs. Hinton et al. introduced this in "Distilling the Knowledge in a Neural Network" (2015). DistilBERT, for example, retains 97 percent of BERT's performance at 60 percent of the size and 40 percent less inference time (Sanh et al., 2019).
- Quantization: Reduce model weights from 32-bit floating point to 8-bit integers. Cuts model size by 4x with typically 1–3 percent accuracy loss. Supported natively by TensorFlow Lite and PyTorch.
- Pruning: Remove low-importance weights from a trained model. Can reduce model size by 50–90 percent depending on the model and the acceptable accuracy threshold.
Turn Learning into Career Growth
Monitoring Over Time: Metric Decay
The metrics you measured during development will degrade after deployment. This is not a failure of your model. It is a fact about how data distributions change.
Data drift means the input distribution at serving time diverges from the training distribution. A fraud model trained on 2023 transaction patterns sees new patterns in 2026.
Concept drift means the relationship between inputs and outputs changes. A pricing model trained in a low-inflation economy produces bad predictions in a high-inflation one.
Production teams monitor both families of metrics continuously:
- Quality metrics on a sampled subset of predictions where ground truth labels are available (usually with a delay of hours to days)
- Runtime metrics on every prediction in real time (latency percentiles, error rates, throughput)
- Drift metrics comparing serving-time input distributions to training-time distributions using statistical tests like KL divergence, Population Stability Index (PSI), or Wasserstein distance
The MLOps pipeline guide covers how to build monitoring infrastructure that catches drift before it becomes a business problem.
For a broader view of where performance metrics fit in the ML lifecycle, the machine learning topics hub connects this reference to model building, evaluation, and deployment resources.
Quality metrics get models built. Performance metrics get them shipped. Learn both in Scaler's AI and ML Program from evaluation fundamentals to production monitoring, with mentor-led guidance across the full ML lifecycle.
FAQs
What are the main performance metrics in machine learning?
There are two families of performance metrics that production ML teams track. The first is prediction quality metrics, which include accuracy, precision, recall, F1 score, and ROC-AUC for classification problems, and MAE, RMSE, and R-squared for regression problems. The second is runtime performance metrics, which include inference latency (measured at P50, P95, and P99 percentiles), throughput in queries per second, model size, and cost per prediction. Both families matter, but most courses only teach the first one.
What is the difference between precision and recall, and when should I use each?
Precision measures how many of your positive predictions were correct, while recall measures how many of the actual positives your model found. Use precision when false positives are more costly than false negatives, such as spam detection where flagging a legitimate email is worse than missing a spam email. Use recall when false negatives are more costly, such as cancer screening where missing a positive case is dangerous. When both matter equally, report the F1 score, which is the harmonic mean of the two.
What is a good inference latency for a deployed ML model?
It depends entirely on the application context. For real-time user-facing systems like search ranking, content recommendation, or fraud detection, a P95 latency target of 50 to 100 milliseconds is standard because delays above 100 milliseconds begin to measurably impact user experience and conversion rates. For batch scoring systems that run offline, latencies of several seconds per prediction are acceptable. For edge and mobile applications like on-device speech recognition, sub-30 millisecond latency is typically required.
Why would a production team choose a less accurate but faster model?
Because user experience and infrastructure cost scale with runtime performance, not with accuracy. A model that is 2 percent less accurate but 5 times faster often produces better business outcomes because the latency improvement increases user engagement and reduces serving costs across millions of predictions. This is why techniques like knowledge distillation, quantization, and pruning are standard practice in production ML they deliberately trade a small accuracy reduction for significant gains in speed and cost.
How do I monitor model performance after deployment?
Production monitoring tracks both metric families continuously over time. Quality metrics are measured on a sampled subset of predictions where ground truth labels become available (usually with a delay), watching for drift that indicates the model's predictions are degrading relative to the training baseline. Runtime metrics like latency percentiles, error rates, and throughput are tracked on every prediction in real time. Drift detection uses statistical tests like Population Stability Index or KL divergence to compare serving-time data distributions against training-time distributions and trigger retraining when divergence crosses a defined threshold.
Which performance metric should I report in a job interview project?
Report the metric that matches your problem's cost structure rather than defaulting to accuracy. For imbalanced classification problems, report F1 score or precision-recall with a confusion matrix. For regression problems, report both RMSE and MAE and explain what the gap between them tells you about error distribution. If you deployed the model, also report P95 inference latency and throughput very few candidates mention runtime metrics, and interviewers at product companies specifically listen for this because it signals that you understand the difference between a model that works in a notebook and one that works in production.





