bichle commited on
Commit
ebdceac
·
verified ·
1 Parent(s): 0b89353

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py CHANGED
@@ -152,6 +152,19 @@ load_css()
152
  # --- 3. DATA & MODEL LOADING FUNCTIONS (WITH CACHING) ---
153
  # Checklist Items 1 & 2: Cache all heavy operations
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  @st.cache_data
156
  def load_hourly_data(file_path="data/final_hourly_feature_dataset.csv"):
157
  """Loads the Hourly Direct dataset using the provided demo file."""
@@ -301,6 +314,7 @@ HOURLY_TARGET_COLS = ['target_temp_next_24h', 'target_temp_next_48h', 'target_te
301
 
302
  # Load models và data mới
303
  hourly_data_df = load_hourly_data(file_path="data/final_hourly_feature_dataset.csv") # Dùng tên file features chính xác
 
304
  hourly_models_24h = load_24_hourly_models() # Dùng 24 mô hình LGBM
305
  # Tạo input features cho Hourly
306
  if not hourly_data_df.empty:
@@ -835,6 +849,36 @@ with tab4:
835
  )
836
  st.plotly_chart(fig_hourly, use_container_width=True)
837
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
838
  # 6. Hiển thị Features Dùng để Dự đoán (Giữ nguyên)
839
  st.markdown("---")
840
  with st.expander("🔍 Feature Inspector: Hourly Inputs for the Forecast"):
 
152
  # --- 3. DATA & MODEL LOADING FUNCTIONS (WITH CACHING) ---
153
  # Checklist Items 1 & 2: Cache all heavy operations
154
 
155
+ @st.cache_data
156
+ def load_hourly_performance_data(file_path="data/hourly_120h_evaluation_results.csv"):
157
+ """Loads hourly RMSE/R2 performance data (T+1h to T+120h)."""
158
+ try:
159
+ df = pd.read_csv(file_path)
160
+ # Giả định cột đầu tiên là Horizon (1, 2, 3...)
161
+ df['Horizon'] = df.index + 1
162
+ # Giữ nguyên code này ngay cả khi cột Horizon đã có sẵn
163
+ return df
164
+ except FileNotFoundError:
165
+ st.warning(f"Warning: Hourly Performance data not found at: {file_path}. Cannot show degradation plot.")
166
+ return pd.DataFrame()
167
+
168
  @st.cache_data
169
  def load_hourly_data(file_path="data/final_hourly_feature_dataset.csv"):
170
  """Loads the Hourly Direct dataset using the provided demo file."""
 
314
 
315
  # Load models và data mới
316
  hourly_data_df = load_hourly_data(file_path="data/final_hourly_feature_dataset.csv") # Dùng tên file features chính xác
317
+ hourly_perf_df = load_hourly_performance_data(file_path="data/hourly_120h_evaluation_results.csv") # File hiệu suất
318
  hourly_models_24h = load_24_hourly_models() # Dùng 24 mô hình LGBM
319
  # Tạo input features cho Hourly
320
  if not hourly_data_df.empty:
 
849
  )
850
  st.plotly_chart(fig_hourly, use_container_width=True)
851
 
852
+ # --- NEW GRAPH 1: RMSE Degradation Plot (Reliability) ---
853
+ st.subheader("Model Reliability: Error Degradation")
854
+ if not hourly_perf_df.empty:
855
+ # SỬ DỤNG DỮ LIỆU HIỆU SUẤT THEO GIỜ (120H)
856
+
857
+ # Chỉ lấy 24 giờ đầu tiên nếu bạn muốn tập trung vào 24h forecast
858
+ # Nếu muốn hiển thị 120h, hãy bỏ .head(24)
859
+ df_plot = hourly_perf_df.head(24)
860
+
861
+ # Giả định các cột là 'Horizon' và 'RMSE'
862
+ fig_rmse_hourly = go.Figure()
863
+ fig_rmse_hourly.add_trace(go.Scatter(
864
+ x=df_plot['Horizon'],
865
+ y=df_plot['RMSE'],
866
+ mode='lines+markers',
867
+ name='RMSE',
868
+ line=dict(color='#005aa7')
869
+ ))
870
+ fig_rmse_hourly.update_layout(
871
+ title="RMSE Degradation: Forecast Error vs. Hour Ahead (T+1h to T+24h)",
872
+ xaxis_title="Forecast Horizon (Hours)",
873
+ yaxis_title="RMSE (°C)",
874
+ template="plotly_white",
875
+ yaxis_range=[0, df_plot['RMSE'].max() * 1.1 if not df_plot['RMSE'].empty else 1],
876
+ height=400 # Chiều cao cố định để cân đối với biểu đồ khác
877
+ )
878
+ st.plotly_chart(fig_rmse_hourly, use_container_width=True)
879
+ else:
880
+ st.warning("Could not load Hourly RMSE Degradation data from hourly_120h_evaluation_results.csv.")
881
+
882
  # 6. Hiển thị Features Dùng để Dự đoán (Giữ nguyên)
883
  st.markdown("---")
884
  with st.expander("🔍 Feature Inspector: Hourly Inputs for the Forecast"):