0
0
PyTorchml~8 mins

Why deployment serves predictions in PyTorch - Why Metrics Matter

Choose your learning style9 modes available
Metrics & Evaluation - Why deployment serves predictions
Which metric matters for this concept and WHY

When a model is deployed to serve predictions, the key metric is latency and accuracy. Latency means how fast the model gives answers. Accuracy means how correct those answers are. We want predictions to be both fast and correct because users expect quick and reliable results in real life, like when using a voice assistant or a recommendation system.

Confusion matrix or equivalent visualization (ASCII)
Confusion Matrix Example for a Deployed Model:

          Predicted
          Pos   Neg
Actual Pos  85    15
       Neg  10    90

- True Positives (TP): 85
- False Positives (FP): 10
- True Negatives (TN): 90
- False Negatives (FN): 15

Total samples = 85 + 15 + 10 + 90 = 200

Precision = TP / (TP + FP) = 85 / (85 + 10) = 0.894
Recall = TP / (TP + FN) = 85 / (85 + 15) = 0.85
F1 Score = 2 * (Precision * Recall) / (Precision + Recall) ≈ 0.871
    
Precision vs Recall tradeoff with concrete examples

In deployment, choosing between precision and recall depends on the task:

  • Spam filter: High precision is important. We want to avoid marking good emails as spam (false positives).
  • Medical diagnosis: High recall is important. We want to catch as many sick patients as possible (few false negatives).

Deployment must balance these based on what matters more to users. For example, a slow but very accurate model might frustrate users, while a fast but inaccurate model might give wrong answers.

What "good" vs "bad" metric values look like for this use case

Good deployment metrics:

  • Accuracy above 85% (depends on problem)
  • Latency under 100 milliseconds for real-time apps
  • Balanced precision and recall (e.g., both above 80%)

Bad deployment metrics:

  • Accuracy below 60% (model guesses too often)
  • Latency over 1 second (slow response frustrates users)
  • Very low recall or precision (model misses many cases or gives many wrong answers)
Metrics pitfalls (accuracy paradox, data leakage, overfitting indicators)
  • Accuracy paradox: High accuracy can be misleading if data is unbalanced. For example, if 95% of data is negative, a model always predicting negative gets 95% accuracy but is useless.
  • Data leakage: If the model sees test data during training, metrics look better but real deployment will fail.
  • Overfitting: Model performs well on training data but poorly on new data, causing bad deployment results.
  • Ignoring latency: A model with great accuracy but slow predictions hurts user experience.
Self-check: Your model has 98% accuracy but 12% recall on fraud. Is it good?

No, it is not good for fraud detection. Even though accuracy is high, recall is very low. This means the model misses 88% of fraud cases, which is dangerous. In fraud detection, catching fraud (high recall) is more important than just being right most of the time.

Key Result
Deployment metrics focus on balancing fast prediction speed (latency) with reliable accuracy and recall for user satisfaction.