Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
app.py
CHANGED
|
@@ -152,10 +152,11 @@ def build_variance_plot(expl):
|
|
| 152 |
|
| 153 |
def build_hist_box(df: pd.DataFrame, color_key: str):
|
| 154 |
series = df[color_key].dropna()
|
| 155 |
-
|
| 156 |
-
fig_hist.
|
| 157 |
-
|
| 158 |
-
fig_box.
|
|
|
|
| 159 |
return fig_hist, fig_box
|
| 160 |
|
| 161 |
# -------------------- Controllers --------------------
|
|
@@ -166,7 +167,6 @@ def controller(color_label="BMI (Body Mass Index)", n_components=10, standardize
|
|
| 166 |
color_vals = df[color_key].values
|
| 167 |
|
| 168 |
fig_biplot = build_biplot_plotly(df, Z, loadings, feats, color_key, arrow_scale=arrow_scale)
|
| 169 |
-
# 3D (minstens 3 componenten)
|
| 170 |
if Z.shape[1] < 3:
|
| 171 |
pca3 = PCA(n_components=3); Z3 = pca3.fit_transform(Xs)
|
| 172 |
else:
|
|
@@ -175,7 +175,6 @@ def controller(color_label="BMI (Body Mass Index)", n_components=10, standardize
|
|
| 175 |
fig_variance = build_variance_plot(expl)
|
| 176 |
fig_hist, fig_box = build_hist_box(df, color_key)
|
| 177 |
|
| 178 |
-
# Tabel top-features
|
| 179 |
load_df = pd.DataFrame({
|
| 180 |
"feature_key": feats,
|
| 181 |
"PC1_loading": loadings[:, 0],
|
|
@@ -279,10 +278,10 @@ with gr.Blocks(title="PCA Dashboard — Diabetes (netjes & compleet)") as demo:
|
|
| 279 |
with gr.Row():
|
| 280 |
with gr.Column():
|
| 281 |
gr.Markdown("### Biplot (2D, hover)")
|
| 282 |
-
plot_biplot = gr.
|
| 283 |
with gr.Column():
|
| 284 |
gr.Markdown("### 3D PCA (PC1–PC3)")
|
| 285 |
-
plot3d = gr.
|
| 286 |
with gr.Row():
|
| 287 |
with gr.Column():
|
| 288 |
gr.Markdown("### Uitlegvariantie")
|
|
@@ -293,10 +292,10 @@ with gr.Blocks(title="PCA Dashboard — Diabetes (netjes & compleet)") as demo:
|
|
| 293 |
with gr.Row():
|
| 294 |
with gr.Column():
|
| 295 |
gr.Markdown("### Histogram")
|
| 296 |
-
plot_hist = gr.
|
| 297 |
with gr.Column():
|
| 298 |
gr.Markdown("### Boxplot")
|
| 299 |
-
plot_box = gr.
|
| 300 |
with gr.Row():
|
| 301 |
with gr.Column():
|
| 302 |
gr.Markdown("### Overzicht (gemiddelden & verdeling)")
|
|
|
|
| 152 |
|
| 153 |
def build_hist_box(df: pd.DataFrame, color_key: str):
|
| 154 |
series = df[color_key].dropna()
|
| 155 |
+
label = FEATURE_LABELS.get(color_key, color_key)
|
| 156 |
+
fig_hist = px.histogram(x=series, nbins=30, title=f"Histogram — {label}", labels={"x": label})
|
| 157 |
+
fig_hist.update_layout(xaxis_title=label, yaxis_title="Aantal", margin=dict(l=10, r=10, t=40, b=10))
|
| 158 |
+
fig_box = px.box(y=series, points="outliers", title=f"Boxplot — {label}", labels={"y": label})
|
| 159 |
+
fig_box.update_layout(yaxis_title=label, margin=dict(l=10, r=10, t=40, b=10))
|
| 160 |
return fig_hist, fig_box
|
| 161 |
|
| 162 |
# -------------------- Controllers --------------------
|
|
|
|
| 167 |
color_vals = df[color_key].values
|
| 168 |
|
| 169 |
fig_biplot = build_biplot_plotly(df, Z, loadings, feats, color_key, arrow_scale=arrow_scale)
|
|
|
|
| 170 |
if Z.shape[1] < 3:
|
| 171 |
pca3 = PCA(n_components=3); Z3 = pca3.fit_transform(Xs)
|
| 172 |
else:
|
|
|
|
| 175 |
fig_variance = build_variance_plot(expl)
|
| 176 |
fig_hist, fig_box = build_hist_box(df, color_key)
|
| 177 |
|
|
|
|
| 178 |
load_df = pd.DataFrame({
|
| 179 |
"feature_key": feats,
|
| 180 |
"PC1_loading": loadings[:, 0],
|
|
|
|
| 278 |
with gr.Row():
|
| 279 |
with gr.Column():
|
| 280 |
gr.Markdown("### Biplot (2D, hover)")
|
| 281 |
+
plot_biplot = gr.Plotly()
|
| 282 |
with gr.Column():
|
| 283 |
gr.Markdown("### 3D PCA (PC1–PC3)")
|
| 284 |
+
plot3d = gr.Plotly()
|
| 285 |
with gr.Row():
|
| 286 |
with gr.Column():
|
| 287 |
gr.Markdown("### Uitlegvariantie")
|
|
|
|
| 292 |
with gr.Row():
|
| 293 |
with gr.Column():
|
| 294 |
gr.Markdown("### Histogram")
|
| 295 |
+
plot_hist = gr.Plotly()
|
| 296 |
with gr.Column():
|
| 297 |
gr.Markdown("### Boxplot")
|
| 298 |
+
plot_box = gr.Plotly()
|
| 299 |
with gr.Row():
|
| 300 |
with gr.Column():
|
| 301 |
gr.Markdown("### Overzicht (gemiddelden & verdeling)")
|