| 6 | |
| 7 | |
| 8 | def plot_prediction(kline_df, pred_df): |
| 9 | pred_df.index = kline_df.index[-pred_df.shape[0]:] |
| 10 | sr_close = kline_df['close'] |
| 11 | sr_pred_close = pred_df['close'] |
| 12 | sr_close.name = 'Ground Truth' |
| 13 | sr_pred_close.name = "Prediction" |
| 14 | |
| 15 | sr_volume = kline_df['volume'] |
| 16 | sr_pred_volume = pred_df['volume'] |
| 17 | sr_volume.name = 'Ground Truth' |
| 18 | sr_pred_volume.name = "Prediction" |
| 19 | |
| 20 | close_df = pd.concat([sr_close, sr_pred_close], axis=1) |
| 21 | volume_df = pd.concat([sr_volume, sr_pred_volume], axis=1) |
| 22 | |
| 23 | fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 6), sharex=True) |
| 24 | |
| 25 | ax1.plot(close_df['Ground Truth'], label='Ground Truth', color='blue', linewidth=1.5) |
| 26 | ax1.plot(close_df['Prediction'], label='Prediction', color='red', linewidth=1.5) |
| 27 | ax1.set_ylabel('Close Price', fontsize=14) |
| 28 | ax1.legend(loc='lower left', fontsize=12) |
| 29 | ax1.grid(True) |
| 30 | |
| 31 | ax2.plot(volume_df['Ground Truth'], label='Ground Truth', color='blue', linewidth=1.5) |
| 32 | ax2.plot(volume_df['Prediction'], label='Prediction', color='red', linewidth=1.5) |
| 33 | ax2.set_ylabel('Volume', fontsize=14) |
| 34 | ax2.legend(loc='upper left', fontsize=12) |
| 35 | ax2.grid(True) |
| 36 | |
| 37 | plt.tight_layout() |
| 38 | plt.show() |
| 39 | |
| 40 | |
| 41 | # 1. Load Model and Tokenizer |