0
0
ML Pythonml~8 mins

Train-test split for time series in ML Python - Model Metrics & Evaluation

Choose your learning style9 modes available
Metrics & Evaluation - Train-test split for time series
Which metric matters for train-test split in time series and WHY

In time series, the order of data is important. We split data by time, not randomly. This means the test set is always later in time than the train set. Metrics like Mean Absolute Error (MAE), Root Mean Squared Error (RMSE), or for classification Precision and Recall are used to measure how well the model predicts future data.

We focus on metrics that show how well the model predicts unseen future points because time series models must generalize forward in time.

Confusion matrix or equivalent visualization

For classification time series, a confusion matrix shows:

      | Predicted Positive | Predicted Negative |
      |--------------------|--------------------|
      | True Positive (TP)  | False Positive (FP) |
      | False Negative (FN) | True Negative (TN)  |
    

For regression time series, we use error metrics like:

      MAE = (1/n) * Σ |y_true - y_pred|
      RMSE = sqrt((1/n) * Σ (y_true - y_pred)^2)
    

These measure how far predictions are from actual future values.

Precision vs Recall tradeoff with concrete examples

In time series classification, precision and recall tradeoff matters depending on the problem:

  • High precision: If you predict an event (like a machine failure), you want to be sure it really happens. False alarms (false positives) are costly.
  • High recall: If missing an event is dangerous (like predicting floods), you want to catch all events, even if some false alarms happen.

Choosing which metric to prioritize depends on the cost of false positives vs false negatives in your time series problem.

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

For time series train-test split:

  • Good: Test error (MAE, RMSE) is close to train error, showing the model predicts future data well without overfitting.
  • Bad: Test error is much higher than train error, meaning the model fails to generalize forward in time.
  • For classification, precision and recall above 0.8 are usually good, but it depends on the problem.
Metrics pitfalls
  • Random split: Splitting time series data randomly breaks time order and leaks future info into training, giving overly optimistic metrics.
  • Ignoring seasonality: Not accounting for time patterns can cause misleading metrics.
  • Overfitting: Very low train error but high test error means the model memorizes past data but fails on future data.
  • Accuracy paradox: High accuracy can be misleading if data is imbalanced (e.g., many no-event days).
Self-check question

Your time series model has 98% accuracy but only 12% recall on rare event detection in the test set. Is it good for production? Why or why not?

Answer: No, it is not good. The model misses 88% of actual events (low recall), which is dangerous if events are important. High accuracy is misleading because most data points are no-event. You should improve recall to catch more events.

Key Result
In time series train-test split, preserving time order is key; metrics like MAE, RMSE, precision, and recall must reflect true future prediction performance without data leakage.