Principle:Shiyu coder Kronos Prediction Visualization
| Field | Value |
|---|---|
| Principle Name | Prediction_Visualization |
| Repository | Shiyu_coder_Kronos |
| Repository URL | https://github.com/shiyu-coder/Kronos |
| Domains | Visualization, Financial_Forecasting |
| Implemented By | Implementation:Shiyu_coder_Kronos_Plot_Prediction_Pattern |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
This principle describes the standard approach for overlaying predicted candlestick values (close price, volume) against ground truth data using matplotlib, enabling visual evaluation of Kronos time series forecasts.
Concept
After generating predictions with KronosPredictor, the results need to be visually compared against actual market data. The visualization overlays predictions on top of ground truth in a multi-subplot layout, with each subplot dedicated to a different data channel.
Theory
The standard time series forecast visualization pattern consists of:
1. Index Alignment
The prediction DataFrame (pred_df) must be aligned to the same index as the corresponding portion of the ground truth DataFrame. This is achieved by assigning the last pred_len rows of the ground truth index to the prediction DataFrame:
pred_df.index = kline_df.index[-pred_df.shape[0]:]
This ensures both DataFrames share a common x-axis for proper overlay.
2. Multi-Channel Subplots
Financial time series typically involve multiple channels (price, volume). Each channel gets its own subplot:
- Close price subplot: Shows the price trajectory, which is the primary signal for trading decisions.
- Volume subplot: Shows trading activity, which provides context for price movements.
Subplots share the x-axis to enable synchronized temporal navigation.
3. Color Coding
A consistent color scheme distinguishes ground truth from predictions:
- Blue: Ground truth (full historical + future data)
- Red: Model predictions (forecast period only)
The ground truth line spans the entire time range (including the lookback window), while the prediction line covers only the forecast horizon. This makes it easy to see where the prediction begins and how it compares to actual values.
4. Concatenation Approach
Ground truth and prediction Series for each channel are concatenated into a single DataFrame before plotting. Since the prediction only overlaps with the tail portion of the ground truth, the concatenation produces NaN values where data does not overlap, resulting in clean overlay rendering by matplotlib.
Visual Layout
+------------------------------------------+ | Close Price | | [Blue line: Ground Truth] | | [Red line: Prediction overlay at tail] | | Legend: Ground Truth | Prediction | +------------------------------------------+ | Volume | | [Blue line: Ground Truth] | | [Red line: Prediction overlay at tail] | | Legend: Ground Truth | Prediction | +------------------------------------------+
See Also
- Implementation:Shiyu_coder_Kronos_Plot_Prediction_Pattern -- The code pattern implementing this visualization
- Principle:Shiyu_coder_Kronos_Candlestick_Data_Preparation -- Data preparation that precedes prediction and visualization