attilabalint
commited on
Commit
·
f87d2ee
1
Parent(s):
c4ae75a
added performance page
Browse files- .gitignore +1 -0
- .streamlit/secrets.toml +2 -0
- app.py +21 -5
- components.py +235 -6
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.streamlit/
|
.streamlit/secrets.toml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
wandb_entity = "attila-balint-kul"
|
| 2 |
+
wandb_api_key = "70458ee5feafed530c7656bada194778e034813b"
|
app.py
CHANGED
|
@@ -1,10 +1,16 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
from components import
|
| 4 |
import utils
|
| 5 |
|
| 6 |
st.set_page_config(page_title="Electricity Demand Dashboard", layout="wide")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
@st.cache_data(ttl=86400)
|
| 10 |
def fetch_data():
|
|
@@ -34,11 +40,11 @@ with st.sidebar:
|
|
| 34 |
2
|
| 35 |
) # Create two columns within the right column for side-by-side images
|
| 36 |
with left:
|
| 37 |
-
st.image("./images/ku_leuven_logo.png")
|
| 38 |
with right:
|
| 39 |
st.image("./images/energyville_logo.png")
|
| 40 |
|
| 41 |
-
view = st.selectbox("View",
|
| 42 |
|
| 43 |
st.header("Models to include")
|
| 44 |
for model_group, models in model_groups.items():
|
|
@@ -48,5 +54,15 @@ with st.sidebar:
|
|
| 48 |
if to_plot:
|
| 49 |
models_to_plot.add(f"{model_group}.{model_name}")
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
from components import buildings_view, models_view, performance_view
|
| 4 |
import utils
|
| 5 |
|
| 6 |
st.set_page_config(page_title="Electricity Demand Dashboard", layout="wide")
|
| 7 |
|
| 8 |
+
PAGES = [
|
| 9 |
+
"Buildings",
|
| 10 |
+
"Models",
|
| 11 |
+
"Performance",
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
|
| 15 |
@st.cache_data(ttl=86400)
|
| 16 |
def fetch_data():
|
|
|
|
| 40 |
2
|
| 41 |
) # Create two columns within the right column for side-by-side images
|
| 42 |
with left:
|
| 43 |
+
st.image("./images/ku_leuven_logo.png")
|
| 44 |
with right:
|
| 45 |
st.image("./images/energyville_logo.png")
|
| 46 |
|
| 47 |
+
view = st.selectbox("View", PAGES, index=0)
|
| 48 |
|
| 49 |
st.header("Models to include")
|
| 50 |
for model_group, models in model_groups.items():
|
|
|
|
| 54 |
if to_plot:
|
| 55 |
models_to_plot.add(f"{model_group}.{model_name}")
|
| 56 |
|
| 57 |
+
|
| 58 |
+
st.title("EnFoBench - Electricity Demand")
|
| 59 |
+
st.divider()
|
| 60 |
+
|
| 61 |
+
if view == "Buildings":
|
| 62 |
+
buildings_view(data)
|
| 63 |
+
elif view == "Models":
|
| 64 |
+
models_view(data)
|
| 65 |
+
elif view == "Performance":
|
| 66 |
+
performance_view(data, models_to_plot)
|
| 67 |
+
else:
|
| 68 |
+
st.write("Not implemented yet")
|
components.py
CHANGED
|
@@ -1,10 +1,239 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
import streamlit as st
|
| 3 |
+
import plotly.express as px
|
| 4 |
|
| 5 |
|
| 6 |
+
def buildings_view(data):
|
| 7 |
+
buildings = (
|
| 8 |
+
data[
|
| 9 |
+
[
|
| 10 |
+
"unique_id",
|
| 11 |
+
"metadata.cluster_size",
|
| 12 |
+
"metadata.building_class",
|
| 13 |
+
"metadata.location_id",
|
| 14 |
+
"metadata.timezone",
|
| 15 |
+
"dataset.available_history.days",
|
| 16 |
+
]
|
| 17 |
+
]
|
| 18 |
+
.groupby("unique_id")
|
| 19 |
+
.first()
|
| 20 |
+
.rename(
|
| 21 |
+
columns={
|
| 22 |
+
"metadata.cluster_size": "Cluster size",
|
| 23 |
+
"metadata.building_class": "Building class",
|
| 24 |
+
"metadata.location_id": "Location ID",
|
| 25 |
+
"metadata.timezone": "Timezone",
|
| 26 |
+
"dataset.available_history.days": "Available history (days)",
|
| 27 |
+
}
|
| 28 |
+
)
|
| 29 |
+
)
|
| 30 |
|
| 31 |
+
st.metric("Number of buildings", len(buildings))
|
| 32 |
+
st.divider()
|
| 33 |
+
|
| 34 |
+
st.markdown("### Buildings")
|
| 35 |
+
st.dataframe(
|
| 36 |
+
buildings,
|
| 37 |
+
use_container_width=True,
|
| 38 |
+
column_config={
|
| 39 |
+
"Available history (days)": st.column_config.ProgressColumn(
|
| 40 |
+
"Available history (days)",
|
| 41 |
+
help="Available training data during the first prediction.",
|
| 42 |
+
format="%f",
|
| 43 |
+
min_value=0,
|
| 44 |
+
max_value=1000,
|
| 45 |
+
),
|
| 46 |
+
},
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
left, right = st.columns(2, gap="large")
|
| 50 |
+
with left:
|
| 51 |
+
st.markdown("#### Building classes")
|
| 52 |
+
fig = px.pie(
|
| 53 |
+
buildings.groupby("Building class").size().reset_index(),
|
| 54 |
+
values=0,
|
| 55 |
+
names="Building class",
|
| 56 |
+
)
|
| 57 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 58 |
+
|
| 59 |
+
with right:
|
| 60 |
+
st.markdown("#### Timezones")
|
| 61 |
+
fig = px.pie(
|
| 62 |
+
buildings.groupby("Timezone").size().reset_index(),
|
| 63 |
+
values=0,
|
| 64 |
+
names="Timezone",
|
| 65 |
+
)
|
| 66 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def models_view(data):
|
| 70 |
+
models = (
|
| 71 |
+
data[
|
| 72 |
+
[
|
| 73 |
+
"model",
|
| 74 |
+
"cv_config.folds",
|
| 75 |
+
"cv_config.horizon",
|
| 76 |
+
"cv_config.step",
|
| 77 |
+
"cv_config.time",
|
| 78 |
+
"model_info.repository",
|
| 79 |
+
"model_info.tag",
|
| 80 |
+
"model_info.variate_type",
|
| 81 |
+
]
|
| 82 |
+
]
|
| 83 |
+
.groupby("model")
|
| 84 |
+
.first()
|
| 85 |
+
.rename(
|
| 86 |
+
columns={
|
| 87 |
+
"cv_config.folds": "CV Folds",
|
| 88 |
+
"cv_config.horizon": "CV Horizon",
|
| 89 |
+
"cv_config.step": "CV Step",
|
| 90 |
+
"cv_config.time": "CV Time",
|
| 91 |
+
"model_info.repository": "Image Repository",
|
| 92 |
+
"model_info.tag": "Image Tag",
|
| 93 |
+
"model_info.variate_type": "Variate type",
|
| 94 |
+
}
|
| 95 |
+
)
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
st.metric("Number of models", len(models))
|
| 99 |
+
st.divider()
|
| 100 |
+
|
| 101 |
+
st.markdown("### Models")
|
| 102 |
+
st.dataframe(models, use_container_width=True)
|
| 103 |
+
|
| 104 |
+
left, right = st.columns(2, gap="large")
|
| 105 |
+
with left:
|
| 106 |
+
st.markdown("#### Variate types")
|
| 107 |
+
fig = px.pie(
|
| 108 |
+
models.groupby("Variate type").size().reset_index(),
|
| 109 |
+
values=0,
|
| 110 |
+
names="Variate type",
|
| 111 |
+
)
|
| 112 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 113 |
+
|
| 114 |
+
with right:
|
| 115 |
+
st.markdown("#### Frameworks")
|
| 116 |
+
_df = models.copy()
|
| 117 |
+
_df["Framework"] = _df.index.str.split(".").str[0]
|
| 118 |
+
fig = px.pie(
|
| 119 |
+
_df.groupby("Framework").size().reset_index(),
|
| 120 |
+
values=0,
|
| 121 |
+
names="Framework",
|
| 122 |
+
)
|
| 123 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def performance_view(data: pd.DataFrame, models_to_plot: set[str]):
|
| 127 |
+
data_to_plot = data[data["model"].isin(models_to_plot)].sort_values(
|
| 128 |
+
by="model", ascending=True
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
left, right = st.columns(2, gap="small")
|
| 132 |
+
with left:
|
| 133 |
+
metric = st.selectbox("Metric", ["MAE", "RMSE", "MBE", "rMAE"], index=0)
|
| 134 |
+
with right:
|
| 135 |
+
aggregation = st.selectbox(
|
| 136 |
+
"Aggregation", ["min", "mean", "median", "max", "std"], index=1
|
| 137 |
+
)
|
| 138 |
+
st.markdown(f"#### {aggregation.capitalize()} {metric} per building")
|
| 139 |
+
fig = px.box(
|
| 140 |
+
data_to_plot,
|
| 141 |
+
x=f"{metric}.{aggregation}",
|
| 142 |
+
y="model",
|
| 143 |
+
color="model",
|
| 144 |
+
points="all",
|
| 145 |
+
)
|
| 146 |
+
fig.update_layout(showlegend=False, height=40 * len(models_to_plot))
|
| 147 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 148 |
+
|
| 149 |
+
st.divider()
|
| 150 |
+
|
| 151 |
+
left, right = st.columns(2, gap="large")
|
| 152 |
+
with left:
|
| 153 |
+
x_metric = st.selectbox(
|
| 154 |
+
"Metric", ["MAE", "RMSE", "MBE", "rMAE"], index=0, key="x_metric"
|
| 155 |
+
)
|
| 156 |
+
x_aggregation = st.selectbox(
|
| 157 |
+
"Aggregation",
|
| 158 |
+
["min", "mean", "median", "max", "std"],
|
| 159 |
+
index=1,
|
| 160 |
+
key="x_aggregation",
|
| 161 |
+
)
|
| 162 |
+
with right:
|
| 163 |
+
y_metric = st.selectbox(
|
| 164 |
+
"Aggregation", ["MAE", "RMSE", "MBE", "rMAE"], index=1, key="y_metric"
|
| 165 |
+
)
|
| 166 |
+
y_aggregation = st.selectbox(
|
| 167 |
+
"Aggregation",
|
| 168 |
+
["min", "mean", "median", "max", "std"],
|
| 169 |
+
index=1,
|
| 170 |
+
key="y_aggregation",
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
st.markdown(
|
| 174 |
+
f"#### {x_aggregation.capitalize()} {x_metric} vs {y_aggregation.capitalize()} {y_metric}"
|
| 175 |
+
)
|
| 176 |
+
fig = px.scatter(
|
| 177 |
+
data_to_plot,
|
| 178 |
+
x=f"{x_metric}.{x_aggregation}",
|
| 179 |
+
y=f"{y_metric}.{y_aggregation}",
|
| 180 |
+
color="model",
|
| 181 |
+
)
|
| 182 |
+
fig.update_layout(height=600)
|
| 183 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 184 |
+
|
| 185 |
+
st.divider()
|
| 186 |
+
|
| 187 |
+
left, right = st.columns(2, gap="small")
|
| 188 |
+
with left:
|
| 189 |
+
metric = st.selectbox(
|
| 190 |
+
"Metric", ["MAE", "RMSE", "MBE", "rMAE"], index=0, key="table_metric"
|
| 191 |
+
)
|
| 192 |
+
with right:
|
| 193 |
+
aggregation = st.selectbox(
|
| 194 |
+
"Aggregation across folds",
|
| 195 |
+
["min", "mean", "median", "max", "std"],
|
| 196 |
+
index=1,
|
| 197 |
+
key="table_aggregation",
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
metrics_table = data_to_plot.groupby(["model"]).agg(aggregation, numeric_only=True)[
|
| 201 |
+
[
|
| 202 |
+
f"{metric}.min",
|
| 203 |
+
f"{metric}.mean",
|
| 204 |
+
f"{metric}.median",
|
| 205 |
+
f"{metric}.max",
|
| 206 |
+
f"{metric}.std",
|
| 207 |
+
]
|
| 208 |
+
]
|
| 209 |
+
|
| 210 |
+
def custom_table(styler):
|
| 211 |
+
styler.background_gradient(cmap="seismic", axis=0)
|
| 212 |
+
styler.format(precision=2)
|
| 213 |
+
|
| 214 |
+
# center text and increase font size
|
| 215 |
+
styler.map(lambda x: "text-align: center; font-size: 14px;")
|
| 216 |
+
return styler
|
| 217 |
+
|
| 218 |
+
st.markdown(f"#### {aggregation.capitalize()} {metric} stats per model")
|
| 219 |
+
styled_table = metrics_table.style.pipe(custom_table)
|
| 220 |
+
st.dataframe(styled_table, use_container_width=True)
|
| 221 |
+
|
| 222 |
+
metrics_table = (
|
| 223 |
+
data_to_plot.groupby(["model", "unique_id"])
|
| 224 |
+
.apply(aggregation, numeric_only=True)
|
| 225 |
+
.reset_index()
|
| 226 |
+
.pivot(index="model", columns="unique_id", values=f"{metric}.{aggregation}")
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
def custom_table(styler):
|
| 230 |
+
styler.background_gradient(cmap="seismic", axis=None)
|
| 231 |
+
styler.format(precision=2)
|
| 232 |
+
|
| 233 |
+
# center text and increase font size
|
| 234 |
+
styler.map(lambda x: "text-align: center; font-size: 14px;")
|
| 235 |
+
return styler
|
| 236 |
+
|
| 237 |
+
st.markdown(f"#### {aggregation.capitalize()} {metric} stats per building")
|
| 238 |
+
styled_table = metrics_table.style.pipe(custom_table)
|
| 239 |
+
st.dataframe(styled_table, use_container_width=True)
|