20
20
)
21
21
from sklearn .datasets import fetch_openml , load_digits , load_iris
22
22
from sklearn .decomposition import PCA
23
+ from sklearn .preprocessing import StandardScaler
23
24
from umap import UMAP
24
25
25
26
from tdamapper .core import aggregate_graph
@@ -349,6 +350,7 @@ def mapper_lens_input_section(X):
349
350
350
351
def mapper_cover_input_section ():
351
352
st .header ("🌐 Cover" )
353
+ scale_cover = st .checkbox ("Apply Scaling" , value = False , key = "scale_cover" )
352
354
cover_type = st .selectbox (
353
355
"Type" ,
354
356
options = [
@@ -395,7 +397,7 @@ def mapper_cover_input_section():
395
397
elif cover_type == V_COVER_KNN :
396
398
knn_k = st .number_input ("Neighbors" , value = 10 , min_value = 1 )
397
399
cover = KNNCover (neighbors = knn_k )
398
- return cover
400
+ return cover , scale_cover
399
401
400
402
401
403
def mapper_clustering_cover ():
@@ -564,6 +566,7 @@ def mapper_clustering_affinityprop():
564
566
565
567
def mapper_clustering_input_section ():
566
568
st .header ("🧮 Clustering" )
569
+ scale_clustering = st .checkbox ("Apply Scaling" , value = False , key = "scale_clustering" )
567
570
clustering_type = st .selectbox (
568
571
"Type" ,
569
572
options = [
@@ -592,32 +595,36 @@ def mapper_clustering_input_section():
592
595
clustering = mapper_clustering_hdbscan ()
593
596
elif clustering_type == V_CLUSTERING_AFFINITY_PROPAGATION :
594
597
clustering = mapper_clustering_affinityprop ()
595
- return clustering
598
+ return clustering , scale_clustering
596
599
597
600
598
601
@st .cache_data (
599
602
hash_funcs = {"tdamapper.learn.MapperAlgorithm" : MapperAlgorithm .__repr__ },
600
603
show_spinner = "Computing Mapper" ,
601
604
)
602
- def compute_mapper (mapper , X , y ):
605
+ def compute_mapper (mapper , X , y , scale_clustering , scale_cover ):
603
606
logger .info ("Generating Mapper graph" )
607
+ if scale_clustering :
608
+ X = StandardScaler ().fit_transform (X )
609
+ if scale_cover :
610
+ y = StandardScaler ().fit_transform (y )
604
611
mapper_graph = mapper .fit_transform (X , y )
605
612
return mapper_graph
606
613
607
614
608
615
def mapper_input_section (X ):
609
616
lens = mapper_lens_input_section (X )
610
617
st .divider ()
611
- cover = mapper_cover_input_section ()
618
+ cover , scale_cover = mapper_cover_input_section ()
612
619
st .divider ()
613
- clustering = mapper_clustering_input_section ()
620
+ clustering , scale_clustering = mapper_clustering_input_section ()
614
621
mapper_algo = MapperAlgorithm (
615
622
cover = cover ,
616
623
clustering = clustering ,
617
624
verbose = False ,
618
625
n_jobs = - 2 ,
619
626
)
620
- mapper_graph = compute_mapper (mapper_algo , X , lens )
627
+ mapper_graph = compute_mapper (mapper_algo , X , lens , scale_clustering , scale_cover )
621
628
return mapper_graph
622
629
623
630
@@ -707,20 +714,14 @@ def _hash_mapper_plot(mapper_plot):
707
714
hash_funcs = {"tdamapper.plot.MapperPlot" : _hash_mapper_plot },
708
715
show_spinner = "Rendering Mapper" ,
709
716
)
710
- def compute_mapper_fig (mapper_plot , colors , node_size , cmap , _agg , agg_name ):
717
+ def compute_mapper_fig (mapper_plot , colors , _agg , agg_name ):
711
718
logger .info ("Generating Mapper figure" )
712
719
mapper_fig = mapper_plot .plot_plotly (
713
720
colors ,
714
- node_size = [
715
- 0.0 ,
716
- node_size / 2.0 ,
717
- node_size ,
718
- node_size * 1.5 ,
719
- node_size * 2.0 ,
720
- ],
721
+ node_size = [0.25 * i for i in range (9 )],
721
722
agg = _agg ,
722
723
title = [f"{ c } " for c in colors .columns ],
723
- cmap = cmap ,
724
+ cmap = [ "Jet" , "Viridis" , "Cividis" ] ,
724
725
width = 600 ,
725
726
height = 600 ,
726
727
)
@@ -735,9 +736,7 @@ def mapper_figure_section(df_X, df_y, mapper_plot):
735
736
mapper_fig = compute_mapper_fig (
736
737
mapper_plot ,
737
738
colors = colors ,
738
- node_size = 1.0 ,
739
739
_agg = agg ,
740
- cmap = ["Jet" , "Viridis" , "Cividis" ],
741
740
agg_name = agg_name ,
742
741
)
743
742
mapper_fig .update_layout (
0 commit comments