Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,14 +28,13 @@ def load_data_predictions(github_token):
|
|
28 |
'DNN2': 'Neural Network 2',
|
29 |
'DNN3': 'Neural Network 3',
|
30 |
'DNN4': 'Neural Network 4',
|
31 |
-
'DNN_Ensemble': 'Neural Network Ensemble',
|
32 |
'LEAR56': 'Regularized Linear Model 1',
|
33 |
'LEAR84': 'Regularized Linear Model 2',
|
34 |
'LEAR112': 'Regularized Linear Model 3',
|
35 |
'LEAR730': 'Regularized Linear Model 4',
|
36 |
-
'LEAR_Ensemble': 'Regularized Linear Model Ensemble',
|
37 |
'Persis': 'Persistence Model',
|
38 |
-
'Hybrid_Ensemble': 'Hybrid Ensemble'
|
|
|
39 |
})
|
40 |
df['Date'] = pd.to_datetime(df['Date'], dayfirst=True)
|
41 |
df_filtered = df.dropna(subset=['Real Price'])
|
@@ -87,10 +86,10 @@ start_date = end_date - pd.Timedelta(days=7)
|
|
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', '
|
91 |
|
92 |
def conformal_predictions(data):
|
93 |
-
data['Residuals'] = data['
|
94 |
data.set_index('Date', inplace=True)
|
95 |
data['Hour'] = data.index.hour
|
96 |
min_date = data.index.min()
|
@@ -108,8 +107,8 @@ def conformal_predictions(data):
|
|
108 |
hour_quantile = quantiles[hour]
|
109 |
idx = (data.index.normalize() == date) & (data.Hour == hour)
|
110 |
data.loc[idx, 'Quantile_90'] = hour_quantile
|
111 |
-
data.loc[idx, 'Lower_Interval'] = data.loc[idx, '
|
112 |
-
data.loc[idx, 'Upper_Interval'] = data.loc[idx, '
|
113 |
data.reset_index(inplace=True)
|
114 |
return data
|
115 |
|
@@ -137,9 +136,9 @@ upper_space.markdown("""
|
|
137 |
with st.sidebar:
|
138 |
st.write("### Variables Selection for Graph")
|
139 |
st.write("Select which variables you'd like to include in the graph. This will affect the displayed charts and available data for download.")
|
140 |
-
selected_variables = st.multiselect("Select variables to display:", options=['Real Price', 'Neural Network 1', 'Neural Network 2', 'Neural Network 3', 'Neural Network 4', 'Regularized Linear Model 1', 'Regularized Linear Model 2','Regularized Linear Model 3', 'Regularized Linear Model 4', '
|
141 |
st.write("### Model Selection for Scatter Plot")
|
142 |
-
model_selection = st.selectbox("Select which model's predictions to display:", options=['Neural Network 1', 'Neural Network 2', 'Neural Network 3', 'Neural Network 4', 'Regularized Linear Model 1', 'Regularized Linear Model 2','Regularized Linear Model 3', 'Regularized Linear Model 4', '
|
143 |
|
144 |
st.write("### Date Range for Metrics Calculation")
|
145 |
st.write("Select the date range to calculate the metrics for the predictions. This will influence the accuracy metrics displayed below. The complete dataset ranges from 10/03/2024 until today.")
|
@@ -152,7 +151,7 @@ else:
|
|
152 |
st.write("## Belgian Day-Ahead Electricity Prices")
|
153 |
|
154 |
# Call conformal_predictions if 'Hybrid Ensemble' is selected
|
155 |
-
if '
|
156 |
df = conformal_predictions(df) # Make sure this function modifies df correctly
|
157 |
|
158 |
temp_df = df[(df['Date'] >= pd.Timestamp(start_date))] # Ensure correct date filtering
|
@@ -164,7 +163,7 @@ else:
|
|
164 |
fig.add_trace(go.Scatter(x=temp_df['Date'], y=temp_df[variable], mode='lines', name=variable))
|
165 |
|
166 |
# Check if conformal predictions should be added for Hybrid Ensemble
|
167 |
-
if variable == '
|
168 |
# Add the lower interval trace
|
169 |
fig.add_trace(go.Scatter(
|
170 |
x=temp_df['Date'],
|
@@ -234,7 +233,7 @@ if start_date_pred and end_date_pred:
|
|
234 |
models = [
|
235 |
'Neural Network 1', 'Neural Network 2', 'Neural Network 3', 'Neural Network 4',
|
236 |
'Regularized Linear Model 1', 'Regularized Linear Model 2', 'Regularized Linear Model 3', 'Regularized Linear Model 4',
|
237 |
-
'Persistence Model', '
|
238 |
]
|
239 |
|
240 |
# Placeholder for results
|
|
|
28 |
'DNN2': 'Neural Network 2',
|
29 |
'DNN3': 'Neural Network 3',
|
30 |
'DNN4': 'Neural Network 4',
|
|
|
31 |
'LEAR56': 'Regularized Linear Model 1',
|
32 |
'LEAR84': 'Regularized Linear Model 2',
|
33 |
'LEAR112': 'Regularized Linear Model 3',
|
34 |
'LEAR730': 'Regularized Linear Model 4',
|
|
|
35 |
'Persis': 'Persistence Model',
|
36 |
+
'Hybrid_Ensemble': 'Hybrid Ensemble',
|
37 |
+
'Weighted_Ensemble': 'Weighted Ensemble'
|
38 |
})
|
39 |
df['Date'] = pd.to_datetime(df['Date'], dayfirst=True)
|
40 |
df_filtered = df.dropna(subset=['Real Price'])
|
|
|
86 |
models_corr_matrix = ['Real Price', 'Persistence Model', 'Neural Network 1', 'Neural Network 2', 'Neural Network 3',
|
87 |
'Neural Network 4', 'Regularized Linear Model 1',
|
88 |
'Regularized Linear Model 2', 'Regularized Linear Model 3',
|
89 |
+
'Regularized Linear Model 4', 'Weighted Ensemble']
|
90 |
|
91 |
def conformal_predictions(data):
|
92 |
+
data['Residuals'] = data['Weighted Ensemble'] - data['Real Price']
|
93 |
data.set_index('Date', inplace=True)
|
94 |
data['Hour'] = data.index.hour
|
95 |
min_date = data.index.min()
|
|
|
107 |
hour_quantile = quantiles[hour]
|
108 |
idx = (data.index.normalize() == date) & (data.Hour == hour)
|
109 |
data.loc[idx, 'Quantile_90'] = hour_quantile
|
110 |
+
data.loc[idx, 'Lower_Interval'] = data.loc[idx, 'Weighted Ensemble'] - hour_quantile
|
111 |
+
data.loc[idx, 'Upper_Interval'] = data.loc[idx, 'Weighted Ensemble'] + hour_quantile
|
112 |
data.reset_index(inplace=True)
|
113 |
return data
|
114 |
|
|
|
136 |
with st.sidebar:
|
137 |
st.write("### Variables Selection for Graph")
|
138 |
st.write("Select which variables you'd like to include in the graph. This will affect the displayed charts and available data for download.")
|
139 |
+
selected_variables = st.multiselect("Select variables to display:", options=['Real Price', 'Neural Network 1', 'Neural Network 2', 'Neural Network 3', 'Neural Network 4', 'Regularized Linear Model 1', 'Regularized Linear Model 2','Regularized Linear Model 3', 'Regularized Linear Model 4', 'Weighted Ensemble', 'Persistence Model'], default=['Real Price', 'Weighted Ensemble'])
|
140 |
st.write("### Model Selection for Scatter Plot")
|
141 |
+
model_selection = st.selectbox("Select which model's predictions to display:", options=['Neural Network 1', 'Neural Network 2', 'Neural Network 3', 'Neural Network 4', 'Regularized Linear Model 1', 'Regularized Linear Model 2','Regularized Linear Model 3', 'Regularized Linear Model 4', 'Weighted Ensemble', 'Persistence Model'], index=8) # Adjust the index as needed to default to your desired option
|
142 |
|
143 |
st.write("### Date Range for Metrics Calculation")
|
144 |
st.write("Select the date range to calculate the metrics for the predictions. This will influence the accuracy metrics displayed below. The complete dataset ranges from 10/03/2024 until today.")
|
|
|
151 |
st.write("## Belgian Day-Ahead Electricity Prices")
|
152 |
|
153 |
# Call conformal_predictions if 'Hybrid Ensemble' is selected
|
154 |
+
if 'Weighted Ensemble' in selected_variables:
|
155 |
df = conformal_predictions(df) # Make sure this function modifies df correctly
|
156 |
|
157 |
temp_df = df[(df['Date'] >= pd.Timestamp(start_date))] # Ensure correct date filtering
|
|
|
163 |
fig.add_trace(go.Scatter(x=temp_df['Date'], y=temp_df[variable], mode='lines', name=variable))
|
164 |
|
165 |
# Check if conformal predictions should be added for Hybrid Ensemble
|
166 |
+
if variable == 'Weighted Ensemble' and 'Quantile_90' in df.columns:
|
167 |
# Add the lower interval trace
|
168 |
fig.add_trace(go.Scatter(
|
169 |
x=temp_df['Date'],
|
|
|
233 |
models = [
|
234 |
'Neural Network 1', 'Neural Network 2', 'Neural Network 3', 'Neural Network 4',
|
235 |
'Regularized Linear Model 1', 'Regularized Linear Model 2', 'Regularized Linear Model 3', 'Regularized Linear Model 4',
|
236 |
+
'Persistence Model', 'Weighted Ensemble'
|
237 |
]
|
238 |
|
239 |
# Placeholder for results
|