Skip to content

Commit 8cd58f3

Browse files
authored
Merge pull request #196 from lucasimi/develop
Minor tweaks
2 parents 14ebbac + 8350f59 commit 8cd58f3

File tree

1 file changed

+120
-100
lines changed

1 file changed

+120
-100
lines changed

app/streamlit_app.py

+120-100
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def initialize():
158158
'About': ABOUT,
159159
},
160160
)
161+
st.logo(LOGO_URL, size='large', link=GIT_REPO_URL)
161162
with st.sidebar:
162-
st.logo(LOGO_URL, size='large', link=GIT_REPO_URL)
163-
st.markdown('Data exploration with *Mapper*')
163+
st.markdown('*Explore data with Mapper*')
164164
st.header('')
165165

166166

@@ -192,7 +192,7 @@ def data_input_section():
192192
source = None
193193
name = None
194194
csv = None
195-
st.subheader('📦 Data')
195+
st.header('📊 Data')
196196
source = st.selectbox(
197197
'Source',
198198
options=['Example', 'OpenML', 'CSV'],
@@ -211,7 +211,7 @@ def data_input_section():
211211

212212

213213
def mapper_lens_input_section(X):
214-
st.subheader('🔎 Lens')
214+
st.header('🔎 Lens')
215215
lens_type = st.selectbox(
216216
'Type',
217217
options=[
@@ -250,7 +250,7 @@ def mapper_lens_input_section(X):
250250

251251

252252
def mapper_cover_input_section():
253-
st.subheader('🌐 Cover')
253+
st.header('🌐 Cover')
254254
cover_type = st.selectbox(
255255
'Type',
256256
options=[V_COVER_TRIVIAL, V_COVER_BALL, V_COVER_CUBICAL],
@@ -265,12 +265,17 @@ def mapper_cover_input_section():
265265
value=100.0,
266266
min_value=0.0,
267267
)
268-
ball_metric_p = st.number_input(
269-
'$L_p$ metric',
270-
value=2,
271-
min_value=1,
268+
metric = st.selectbox(
269+
'Metric',
270+
options=[
271+
'euclidean',
272+
'chebyshev',
273+
'manhattan',
274+
'cosine',
275+
],
276+
key='cover_metric',
272277
)
273-
cover = BallCover(radius=ball_r, metric=minkowski(ball_metric_p))
278+
cover = BallCover(radius=ball_r, metric=metric)
274279
elif cover_type == V_COVER_CUBICAL:
275280
cubical_n = st.number_input(
276281
'Intervals',
@@ -285,8 +290,105 @@ def mapper_cover_input_section():
285290
return cover
286291

287292

293+
def mapper_clustering_kmeans():
294+
clust_num = st.number_input(
295+
'Clusters',
296+
value=2,
297+
min_value=1,
298+
)
299+
n_clusters = int(clust_num)
300+
return KMeans(n_clusters=n_clusters, n_init='auto')
301+
302+
303+
def mapper_clustering_dbscan():
304+
eps = st.number_input(
305+
'Eps',
306+
value=0.5,
307+
min_value=0.0,
308+
)
309+
min_samples = st.number_input(
310+
'Min Samples',
311+
value=5,
312+
min_value=1,
313+
)
314+
metric = st.selectbox(
315+
'Metric',
316+
options=[
317+
'euclidean',
318+
'chebyshev',
319+
'manhattan',
320+
'cosine',
321+
]
322+
)
323+
return DBSCAN(eps=eps, min_samples=min_samples, metric=metric)
324+
325+
326+
def mapper_clustering_hdbscan():
327+
min_cluster_size = st.number_input(
328+
'Min Cluster Size',
329+
value=5,
330+
min_value=1,
331+
)
332+
metric = st.selectbox(
333+
'Metric',
334+
options=[
335+
'euclidean',
336+
'chebyshev',
337+
'manhattan',
338+
]
339+
)
340+
return HDBSCAN(min_cluster_size=min_cluster_size, metric=metric)
341+
342+
343+
def mapper_clustering_agglomerative():
344+
clust_num = st.number_input(
345+
'Clusters',
346+
value=2,
347+
min_value=1,
348+
)
349+
linkage = st.selectbox(
350+
'Linkage',
351+
options=[
352+
'ward',
353+
'complete',
354+
'average',
355+
'single',
356+
],
357+
index=3,
358+
)
359+
n_clusters = int(clust_num)
360+
metric = st.selectbox(
361+
'Metric',
362+
options=[
363+
'euclidean',
364+
'chebyshev',
365+
'manhattan',
366+
'cosine',
367+
]
368+
)
369+
return AgglomerativeClustering(
370+
n_clusters=n_clusters,
371+
linkage=linkage,
372+
metric=metric,
373+
)
374+
375+
376+
def mapper_clustering_affinityprop():
377+
damping = st.number_input(
378+
'Damping',
379+
value=0.5,
380+
min_value=0.0,
381+
)
382+
max_iter = st.number_input(
383+
'Max Iter',
384+
value=200,
385+
min_value=50,
386+
)
387+
return AffinityPropagation(damping=damping, max_iter=max_iter)
388+
389+
288390
def mapper_clustering_input_section():
289-
st.subheader('🧮 Clustering')
391+
st.header('🧮 Clustering')
290392
clustering_type = st.selectbox(
291393
'Type',
292394
options=[
@@ -303,97 +405,15 @@ def mapper_clustering_input_section():
303405
if clustering_type == V_CLUSTERING_TRIVIAL:
304406
clustering = None
305407
elif clustering_type == V_CLUSTERING_AGGLOMERATIVE:
306-
clust_num = st.number_input(
307-
'Clusters',
308-
value=2,
309-
min_value=1,
310-
)
311-
linkage = st.selectbox(
312-
'Linkage',
313-
options=[
314-
'ward',
315-
'complete',
316-
'average',
317-
'single',
318-
],
319-
index=3,
320-
)
321-
n_clusters = int(clust_num)
322-
metric = st.selectbox(
323-
'Metric',
324-
options=[
325-
'euclidean',
326-
'l1',
327-
'l2',
328-
'manhattan',
329-
'cosine',
330-
]
331-
)
332-
clustering = AgglomerativeClustering(
333-
n_clusters=n_clusters,
334-
linkage=linkage,
335-
metric=metric,
336-
)
408+
clustering = mapper_clustering_agglomerative()
337409
elif clustering_type == V_CLUSTERING_KMEANS:
338-
clust_num = st.number_input(
339-
'Clusters',
340-
value=2,
341-
min_value=1,
342-
)
343-
n_clusters = int(clust_num)
344-
clustering = KMeans(n_clusters=n_clusters, n_init='auto')
410+
clustering = mapper_clustering_kmeans()
345411
elif clustering_type == V_CLUSTERING_DBSCAN:
346-
eps = st.number_input(
347-
'Eps',
348-
value=0.5,
349-
min_value=0.0,
350-
)
351-
min_samples = st.number_input(
352-
'Min Samples',
353-
value=5,
354-
min_value=1,
355-
)
356-
metric = st.selectbox(
357-
'Metric',
358-
options=[
359-
'euclidean',
360-
'l1',
361-
'l2',
362-
'manhattan',
363-
'cosine',
364-
]
365-
)
366-
clustering = DBSCAN(eps=eps, min_samples=min_samples, metric=metric)
412+
clustering = mapper_clustering_dbscan()
367413
elif clustering_type == V_CLUSTERING_HDBSCAN:
368-
min_cluster_size = st.number_input(
369-
'Min Cluster Size',
370-
value=5,
371-
min_value=1,
372-
)
373-
metric = st.selectbox(
374-
'Metric',
375-
options=[
376-
'euclidean',
377-
'l1',
378-
'l2',
379-
'manhattan',
380-
'cosine',
381-
]
382-
)
383-
clustering = HDBSCAN(min_cluster_size=min_cluster_size, metric=metric)
414+
clustering = mapper_clustering_hdbscan()
384415
elif clustering_type == V_CLUSTERING_AFFINITY_PROPAGATION:
385-
damping = st.number_input(
386-
'Damping',
387-
value=0.5,
388-
min_value=0.0,
389-
)
390-
max_iter = st.number_input(
391-
'Max Iter',
392-
value=200,
393-
min_value=50,
394-
)
395-
clustering = AffinityPropagation(damping=damping, max_iter=max_iter)
396-
416+
clustering = mapper_clustering_affinityprop()
397417
return clustering
398418

399419

@@ -406,7 +426,7 @@ def mapper_input_section(X):
406426
mapper_algo = MapperAlgorithm(
407427
cover=cover,
408428
clustering=clustering,
409-
verbose=False,
429+
verbose=True,
410430
n_jobs=1,
411431
)
412432
mapper_graph = mapper_algo.fit_transform(X, lens)
@@ -509,7 +529,7 @@ def plot_dim_input_section():
509529

510530

511531
def plot_input_section(df_X, df_y, mapper_graph):
512-
st.subheader('🎨 Drawing')
532+
st.header('🎨 Plot')
513533
dim = plot_dim_input_section()
514534
seed = plot_seed_input_section()
515535
agg, agg_name = plot_agg_input_section()

0 commit comments

Comments
 (0)