0
0
ML Pythonml~8 mins

Evaluation metrics (RMSE, precision@k) in ML Python - Model Metrics & Evaluation

Choose your learning style9 modes available
Metrics & Evaluation - Evaluation metrics (RMSE, precision@k)
Which metric matters and WHY

RMSE (Root Mean Squared Error) is used when you want to measure how close your model's predicted numbers are to the actual numbers. It tells you the average size of the errors your model makes, with bigger errors counting more. This is great for tasks like predicting prices or temperatures.

Precision@k is important when you want to check how good your model is at picking the top k items that really matter. For example, if your model recommends 5 movies, precision@5 tells you how many of those 5 movies the user actually likes. This is useful in recommendation systems.

Confusion matrix or equivalent visualization

RMSE does not use a confusion matrix because it measures error size for continuous values.

Precision@k can be understood with a simple example:

    Recommended items (k=5): [A, B, C, D, E]
    Relevant items: [B, D, F, G]

    True Positives (TP) = items recommended and relevant = B, D = 2
    False Positives (FP) = items recommended but not relevant = A, C, E = 3

    Precision@5 = TP / k = 2 / 5 = 0.4
    
Precision vs Recall tradeoff with examples

Precision@k focuses on how many of the top k recommended items are actually relevant. It does not consider how many relevant items were missed.

For example, if a music app recommends 5 songs and 4 are liked (high precision), but the user actually likes 20 songs total, recall is low because many liked songs were not recommended.

RMSE focuses on how close predictions are to actual values. Lower RMSE means predictions are closer to true values.

In some cases, improving precision@k might reduce recall, and vice versa. Choosing which to focus on depends on what matters more: showing only good recommendations (precision) or showing most relevant items (recall).

What "good" vs "bad" metric values look like

RMSE: Lower values are better. For example, if predicting house prices in thousands, an RMSE of 5 means on average predictions are off by $5,000. An RMSE of 50 means much worse predictions.

Precision@k: Values range from 0 to 1. A precision@5 of 0.8 means 4 out of 5 recommended items are relevant (good). A precision@5 of 0.2 means only 1 out of 5 is relevant (bad).

Common pitfalls
  • RMSE: Sensitive to outliers. A few large errors can make RMSE very high.
  • Precision@k: Does not consider missed relevant items (recall). High precision but low recall means many relevant items are ignored.
  • Using accuracy for recommendation or regression tasks is misleading.
  • Ignoring the context: a good RMSE depends on the scale of the data.
Self-check question

Your recommendation model has a precision@5 of 0.9 but recall of 0.1. Is it good for production?

Answer: It depends on the goal. High precision@5 means most recommended items are relevant, which is good. But recall of 0.1 means it only finds 10% of all relevant items, missing many. If you want to show only very good recommendations, this might be okay. But if you want to cover more relevant items, this model misses too many.

Key Result
RMSE measures average prediction error size; precision@k measures relevance of top-k recommendations.