Marcel0123 commited on
Commit
6c26cb8
·
verified ·
1 Parent(s): 8fd4d4f

Upload 2 files

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -74,6 +74,7 @@ def pca_biplot(color_label="BMI (Body Mass Index)", arrow_scale=2.0, point_size=
74
 
75
  cvals = df[color_key].values
76
 
 
77
  fig1 = plt.figure(figsize=(7.8, 5.6))
78
  ax = fig1.add_subplot(111)
79
  sc = ax.scatter(Z[:, 0], Z[:, 1], c=cvals, s=point_size, alpha=alpha)
@@ -94,6 +95,7 @@ def pca_biplot(color_label="BMI (Body Mass Index)", arrow_scale=2.0, point_size=
94
  ax.grid(True, linestyle=":", linewidth=0.6)
95
  plt.tight_layout()
96
 
 
97
  fig2 = plt.figure(figsize=(7.8, 3.8))
98
  ax2 = fig2.add_subplot(111)
99
  xs = np.arange(1, len(expl) + 1)
@@ -106,6 +108,7 @@ def pca_biplot(color_label="BMI (Body Mass Index)", arrow_scale=2.0, point_size=
106
  ax2.grid(True, linestyle=":", linewidth=0.6)
107
  plt.tight_layout()
108
 
 
109
  load_df = pd.DataFrame({
110
  "feature_key": feature_keys,
111
  "PC1_loading": loadings[:, 0],
@@ -135,8 +138,17 @@ def pca_biplot(color_label="BMI (Body Mass Index)", arrow_scale=2.0, point_size=
135
  return fig1, fig2, table, summary_md
136
 
137
  with gr.Blocks(title="PCA Biplot — Diabetes (NL labels)") as demo:
 
 
 
 
 
 
 
 
138
  gr.Markdown("# PCA Biplot — Diabetes (NL labels)")
139
- gr.Markdown("In deze demo zie je **live** hoe PCA de data samenvat. De punten zijn patiënten; pijlen laten zien welke metingen (zoals **BMI**, **Bloeddruk**, **Cholesterol**, **Glucose**) de richting van de componenten bepalen. De **kleur** toont standaard **BMI**.")
 
140
 
141
  with gr.Row():
142
  with gr.Column(scale=1):
@@ -148,13 +160,12 @@ with gr.Blocks(title="PCA Biplot — Diabetes (NL labels)") as demo:
148
  n_components = gr.Slider(2, 10, value=10, step=1, label="Aantal PCA-componenten (voor variatieplot)")
149
  standardize = gr.Checkbox(value=True, label="Standaardiseer metingen (aanbevolen)")
150
  run_btn = gr.Button("Update visualisaties")
151
- gr.Markdown("> *Medisch nut:* deze biplot maakt grote hoeveelheden patiëntmetingen direct inzichtelijk.")
152
  with gr.Column(scale=2):
153
  plot_biplot = gr.Plot(label="PCA-biplot — punten + pijlen")
154
  plot_expl = gr.Plot(label="Uitlegvariantie per component")
155
  table = gr.Dataframe(headers=["Feature (PC1)", "Loading PC1", "Feature (PC2)", "Loading PC2"], row_count=6)
156
  summary = gr.Markdown()
157
- medical_md_block = gr.Markdown(MEDICAL_MD)
158
 
159
  inputs = [color_feat, arrow_scale, point_size, alpha, n_components, standardize]
160
  run_btn.click(fn=pca_biplot, inputs=inputs, outputs=[plot_biplot, plot_expl, table, summary])
 
74
 
75
  cvals = df[color_key].values
76
 
77
+ # Biplot
78
  fig1 = plt.figure(figsize=(7.8, 5.6))
79
  ax = fig1.add_subplot(111)
80
  sc = ax.scatter(Z[:, 0], Z[:, 1], c=cvals, s=point_size, alpha=alpha)
 
95
  ax.grid(True, linestyle=":", linewidth=0.6)
96
  plt.tight_layout()
97
 
98
+ # Explained variance plot
99
  fig2 = plt.figure(figsize=(7.8, 3.8))
100
  ax2 = fig2.add_subplot(111)
101
  xs = np.arange(1, len(expl) + 1)
 
108
  ax2.grid(True, linestyle=":", linewidth=0.6)
109
  plt.tight_layout()
110
 
111
+ # Top-features table
112
  load_df = pd.DataFrame({
113
  "feature_key": feature_keys,
114
  "PC1_loading": loadings[:, 0],
 
138
  return fig1, fig2, table, summary_md
139
 
140
  with gr.Blocks(title="PCA Biplot — Diabetes (NL labels)") as demo:
141
+ # Callout styles
142
+ gr.HTML("""
143
+ <style>
144
+ .callout {padding:12px 14px; border-left:4px solid #2563eb; background:#f1f5f9; border-radius:6px; margin: 8px 0 18px;}
145
+ .smallnote {font-size: 0.92em; opacity: 0.85;}
146
+ </style>
147
+ """)
148
+
149
  gr.Markdown("# PCA Biplot — Diabetes (NL labels)")
150
+ # Place the medical text at the very top so it's always visible
151
+ gr.Markdown(MEDICAL_MD)
152
 
153
  with gr.Row():
154
  with gr.Column(scale=1):
 
160
  n_components = gr.Slider(2, 10, value=10, step=1, label="Aantal PCA-componenten (voor variatieplot)")
161
  standardize = gr.Checkbox(value=True, label="Standaardiseer metingen (aanbevolen)")
162
  run_btn = gr.Button("Update visualisaties")
163
+ gr.HTML('<div class="callout smallnote">💡 *Tip:* kies links een meting (bijv. BMI of cholesterol) en klik daarna op <b>Update visualisaties</b>.</div>')
164
  with gr.Column(scale=2):
165
  plot_biplot = gr.Plot(label="PCA-biplot — punten + pijlen")
166
  plot_expl = gr.Plot(label="Uitlegvariantie per component")
167
  table = gr.Dataframe(headers=["Feature (PC1)", "Loading PC1", "Feature (PC2)", "Loading PC2"], row_count=6)
168
  summary = gr.Markdown()
 
169
 
170
  inputs = [color_feat, arrow_scale, point_size, alpha, n_components, standardize]
171
  run_btn.click(fn=pca_biplot, inputs=inputs, outputs=[plot_biplot, plot_expl, table, summary])