mmmapms commited on
Commit
f03d4c1
1 Parent(s): 9d2161a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -20
app.py CHANGED
@@ -84,7 +84,7 @@ max_date_allowed_pred = df_filtered['Date'].max().date()
84
  end_date = df['Date'].max().date()
85
  start_date = end_date - pd.Timedelta(days=7)
86
 
87
- models_corr_matrix = ['Persistence Model', 'Neural Network 1', 'Neural Network 2', 'Neural Network 3',
88
  'Neural Network 4', 'Regularized Linear Model 1',
89
  'Regularized Linear Model 2', 'Regularized Linear Model 3',
90
  'Regularized Linear Model 4', 'Hybrid Ensemble']
@@ -182,12 +182,12 @@ else:
182
  line=dict(width=0),
183
  fill='tonexty', # Fill between this trace and the previous one
184
  fillcolor='rgba(68, 68, 68, 0.3)',
185
- name='Conformal Prediction'
186
  ))
187
 
188
  fig.update_layout(xaxis_title="Date", yaxis_title="Price [EUR/MWh]")
189
  st.plotly_chart(fig, use_container_width=True)
190
- st.write("The graph presented here illustrates the day-ahead electricity price forecasts for Belgium, covering the period from one week ago up to tomorrow.")
191
 
192
 
193
  if not selected_variables:
@@ -204,16 +204,12 @@ else:
204
  fig = go.Figure()
205
  fig.add_trace(go.Scatter(x=plot_df['Real Price'], y=plot_df[model_column], mode='markers', name=f"Real Price vs {model_selection} Predictions"))
206
 
207
- # Calculate the line of best fit
208
  m, b = np.polyfit(plot_df['Real Price'], plot_df[model_column], 1)
209
- # Calculate the y-values based on the line of best fit
210
- regression_line = m * plot_df['Real Price'] + b
211
 
212
- # Format the equation to display as the legend name
213
- equation = f"y = {m:.2f}x + {b:.2f}"
214
 
215
  # Add the line of best fit to the figure with the equation as the legend name
216
- fig.add_trace(go.Scatter(x=plot_df['Real Price'], y=regression_line, mode='lines', name=equation, line=dict(color='black')))
217
 
218
  # Update layout with appropriate titles
219
  fig.update_layout(
@@ -241,7 +237,7 @@ if start_date_pred and end_date_pred:
241
  ]
242
 
243
  # Placeholder for results
244
- results = {'Metric': ['MAE', 'sMAPE', 'RMSE', 'rMAE']}
245
 
246
  p_real = filtered_df['Real Price']
247
 
@@ -251,12 +247,12 @@ if start_date_pred and end_date_pred:
251
  p_pred = filtered_df[model]
252
 
253
  mae = np.mean(np.abs(p_real - p_pred))
254
- smape = 100 * np.mean(np.abs(p_real - p_pred) / ((np.abs(p_real) + np.abs(p_pred)) / 2))
255
- rmse = np.sqrt(np.mean((p_real - p_pred) ** 2))
256
  rmae = mae/np.mean(np.abs(p_real - filtered_df['Persistence Model']))
257
 
258
  # Store the results
259
- results[model] = [f"{mae:.2f}", f"{smape:.2f}%", f"{rmse:.2f}", f"{rmae:.2f}"]
260
 
261
  # Convert the results to a DataFrame for display
262
  metrics_df = pd.DataFrame(results)
@@ -286,12 +282,6 @@ with col2:
286
  st.markdown(r"""
287
  $\text{MAE} = \frac{1}{n}\sum_{i=1}^{n}|y_i - \hat{y}_i|$
288
 
289
-
290
- $\text{sMAPE} =100\frac{1}{n} \sum_{i=1}^{n} \frac{|y_i - \hat{y}_i|}{\left(|y_i| + |\hat{y}_i|\right)/2}$
291
-
292
-
293
- $\text{RMSE} = \sqrt{\frac{1}{n}\sum_{i=1}^{n}\left(y_i - \hat{y}_i\right)^2}$
294
-
295
 
296
  $\text{rMAE} = \frac{\text{MAE}}{MAE_{\text{Persistence Model}}}$
297
  """)
@@ -313,4 +303,4 @@ fig.update_layout(
313
  st.plotly_chart(fig, use_container_width=True)
314
 
315
  st.write("## Access Predictions")
316
- st.write("If you are interested in accessing the predictions made by the models, please contact Margarida Mascarenhas (KU Leuven PhD Student) at margarida.mascarenhas@kuleuven.be")
 
84
  end_date = df['Date'].max().date()
85
  start_date = end_date - pd.Timedelta(days=7)
86
 
87
+ models_corr_matrix = ['Real Price', 'Persistence Model', 'Neural Network 1', 'Neural Network 2', 'Neural Network 3',
88
  'Neural Network 4', 'Regularized Linear Model 1',
89
  'Regularized Linear Model 2', 'Regularized Linear Model 3',
90
  'Regularized Linear Model 4', 'Hybrid Ensemble']
 
182
  line=dict(width=0),
183
  fill='tonexty', # Fill between this trace and the previous one
184
  fillcolor='rgba(68, 68, 68, 0.3)',
185
+ name='P10/P90 prediction intervals'
186
  ))
187
 
188
  fig.update_layout(xaxis_title="Date", yaxis_title="Price [EUR/MWh]")
189
  st.plotly_chart(fig, use_container_width=True)
190
+ st.write("The graph presented here illustrates the day-ahead electricity price forecasts for Belgium, covering the period from one week ago up to tomorrow. The forecasts are made every morning on day D at 08.00 for day D+1.")
191
 
192
 
193
  if not selected_variables:
 
204
  fig = go.Figure()
205
  fig.add_trace(go.Scatter(x=plot_df['Real Price'], y=plot_df[model_column], mode='markers', name=f"Real Price vs {model_selection} Predictions"))
206
 
 
207
  m, b = np.polyfit(plot_df['Real Price'], plot_df[model_column], 1)
 
 
208
 
209
+ regression_line = m * plot_df['Real Price'] + b
 
210
 
211
  # Add the line of best fit to the figure with the equation as the legend name
212
+ fig.add_trace(go.Scatter(x=plot_df['Real Price'], y=regression_line, mode='lines', line=dict(color='black')))
213
 
214
  # Update layout with appropriate titles
215
  fig.update_layout(
 
237
  ]
238
 
239
  # Placeholder for results
240
+ results = {'Metric': ['MAE', 'rMAE']} #'sMAPE', 'RMSE',
241
 
242
  p_real = filtered_df['Real Price']
243
 
 
247
  p_pred = filtered_df[model]
248
 
249
  mae = np.mean(np.abs(p_real - p_pred))
250
+ #smape = 100 * np.mean(np.abs(p_real - p_pred) / ((np.abs(p_real) + np.abs(p_pred)) / 2))
251
+ #rmse = np.sqrt(np.mean((p_real - p_pred) ** 2))
252
  rmae = mae/np.mean(np.abs(p_real - filtered_df['Persistence Model']))
253
 
254
  # Store the results
255
+ results[model] = [f"{mae:.2f}", f"{rmae:.2f}"] #f"{smape:.2f}%", f"{rmse:.2f}",
256
 
257
  # Convert the results to a DataFrame for display
258
  metrics_df = pd.DataFrame(results)
 
282
  st.markdown(r"""
283
  $\text{MAE} = \frac{1}{n}\sum_{i=1}^{n}|y_i - \hat{y}_i|$
284
 
 
 
 
 
 
 
285
 
286
  $\text{rMAE} = \frac{\text{MAE}}{MAE_{\text{Persistence Model}}}$
287
  """)
 
303
  st.plotly_chart(fig, use_container_width=True)
304
 
305
  st.write("## Access Predictions")
306
+ st.write("If you are interested in accessing the predictions made by the models, the models themselves or how these can be incorporated into your workflows, please contact Margarida Mascarenhas (PhD Student, KU Leuven) at margarida.mascarenhas@kuleuven.be or Hussain Kazmi (assistant professor, KU Leuven) at hussain.kazmi@kuleuven.be.")