Full PyCVI pipeline
Here is an example using exclusively PyCVI for the entire clustering pipeline. The preprocessing steps and the clustering steps can be integrated into the PyCVI pipeline by providing sklearn-like classes of clustering models (e.g. KMeans) and data preprocessor (e.g. StandardScaler).
In this example, we use time-series data and non-time-series data. In addition we use classes from scikit-learn, scikit-learn extra and aeon in order to illustrate the compatibility of PyCVI with sklearn-like libraries.
If you wish to run the example scripts on your own computer, please first follow the instructions detailed in Running example scripts on your computer.
1
2import numpy as np
3import time
4from sklearn.cluster import AgglomerativeClustering, KMeans
5from sklearn.preprocessing import StandardScaler
6from aeon.clustering import TimeSeriesKMeans
7
8from pycvi.cluster import generate_all_clusterings, get_clustering
9from pycvi.cvi import CVIs
10from pycvi.compute_scores import compute_all_scores
11from pycvi.vi import variation_information
12from pycvi.datasets.benchmark import load_data
13from pycvi.exceptions import SelectionError
14
15from pycvi_examples_utils import plot_true_best, plot_selected_clusters
16
17def pipeline(
18 X: np.ndarray,
19 y: np.ndarray,
20 model_class,
21 model_kw: dict,
22 k_max: int = 25,
23 scaler = StandardScaler(),
24 ts_dist:bool = False,
25 fig_title: str = "",
26 fig_name: str = "",
27) -> None:
28 """
29 This function gives an example of using most of PyCVI's features.
30
31 In this full example, we assume that we have access to the real
32 labels of the datapoints. In this function we:
33
34 - Standardize the data
35 - Generate all clusterings for a given range of number of clusters.
36 - Compute the Variation of Information (VI) between the generated
37 clusterings and the true clustering
38 - For each CVI available in PyCVI, compute their values for all
39 generated clusterings
40 - For each CVI, select the best clustering according to its CVI
41 values
42 - Create a summary plot containing the true clustering, the
43 clustering assuming the correct number of clusters and the
44 selected clusterings of each CVI.
45 """
46 print(f'\n ***** {fig_title} ***** \n')
47 k_range = range(k_max)
48
49 # ------------------------------------------------------------------
50 # ------------------ Define true clustering -----------------------
51 # ------------------------------------------------------------------
52 # From the label for each datapoint to a list of
53 # datapoints for each cluster.
54 # true clusters: List[List[int]]
55 true_clusters = get_clustering(y)
56 k_true = len(true_clusters)
57
58 # ------------------------------------------------------------------
59 # ------------------ Generate clusterings -------------------------
60 # ------------------------------------------------------------------
61
62 t_start = time.time()
63
64 clusterings = generate_all_clusterings(
65 X,
66 model_class,
67 model_kw=model_kw,
68 n_clusters_range = k_range,
69 ts_dist = ts_dist,
70 scaler=scaler,
71 )
72
73 t_end = time.time()
74 dt = t_end - t_start
75
76 print(f"Clusterings generated in: {dt:.2f}s")
77
78 # ------------------------------------------------------------------
79 # ------ Variation of information with the true clustering --------
80 # ------------------------------------------------------------------
81
82 best_clusters = clusterings[k_true]
83 VI_best = variation_information(true_clusters, best_clusters)
84
85 # -- Plot true clusters & clusters when assuming k_true clusters ---
86 fig = plot_true_best(X, y, best_clusters, VI_best)
87
88 print(" ================ VI ================ ")
89 # Compute VI between the true clustering and each clustering
90 # obtained with the different clustering methods
91 VIs = {}
92 for k, clustering in clusterings.items():
93 VIs[k] = variation_information(true_clusters, clustering)
94 print(k, VIs[k])
95
96 # ------------------------------------------------------------------
97 # ------------ Compute CVI values and select k ---------------------
98 # ------------------------------------------------------------------
99 ax_titles = []
100 clusterings_selected = []
101
102 for cvi_class in CVIs:
103
104 # Instantiate a CVI model
105 cvi = cvi_class()
106 t_start = time.time()
107 print(f" ====== {cvi} ====== ")
108
109 # Compute CVI values for all clusterings
110 scores = compute_all_scores(
111 cvi,
112 X,
113 clusterings,
114 ts_dist=ts_dist,
115 scaler=StandardScaler(),
116 )
117
118 t_end = time.time()
119 dt = t_end - t_start
120
121 # Print CVI values and selected k
122 for k in clusterings:
123 print(k, scores[k])
124 print('Code executed in %.2f s' %(dt))
125
126 # Select k
127 try:
128 k_selected = cvi.select(scores)
129 except SelectionError as e:
130 k_selected = None
131 clusterings_selected.append(None)
132 ax_titles.append(
133 f"{cvi}, No clustering could be selected."
134 )
135 else:
136 clusterings_selected.append(clusterings[k_selected])
137 ax_titles.append(
138 f"{cvi}, k={k_selected}, VI={VIs[k_selected]:.2f}"
139 )
140 finally:
141 print(f"Selected k: {k_selected} | True k: {k_true}")
142 # ------------------------------------------------------------------
143 # ----------------------- Summary plot -----------------------------
144 # ------------------------------------------------------------------
145
146 fig = plot_selected_clusters(X, clusterings_selected, fig, ax_titles)
147 fig.suptitle(fig_title)
148 fig.savefig(fig_name + ".png")
149
150# ======================================================================
151# PyCVI on non time-series data
152# ======================================================================
153
154# ------------- KMeans ------------------------
155X, y = load_data("zelnik1", "barton")
156ts_dist = False
157k_max = 10
158
159model_class = KMeans
160model_kw = {}
161scaler = StandardScaler()
162
163fig_title = "Non time-series data with KMeans"
164fig_name = "full-Barton_data_KMeans"
165pipeline(X, y, model_class, model_kw, k_max, scaler, ts_dist, fig_title, fig_name)
166
167# --------- AgglomerativeClustering ----------
168X, y = load_data("zelnik1", "barton")
169ts_dist = False
170k_max = 10
171
172model_class = AgglomerativeClustering
173
174# Custom kwargs for sklearn.cluster.AgglomerativeClustering
175model_kw = {"linkage" : "single"}
176scaler = StandardScaler()
177
178fig_title = "Non time-series data with AgglomerativeClustering-Single"
179fig_name = "full-Barton_data_AgglomerativeClustering_Single"
180
181pipeline(X, y, model_class, model_kw, k_max, scaler, ts_dist, fig_title, fig_name)
182
183# ======================================================================
184# PyCVI on time series data
185# ======================================================================
186
187X, y = load_data("Trace", "UCR")
188
189# ==========================
190# PyCVI using a time series distance
191# ==========================
192
193ts_dist = True
194
195model_class = TimeSeriesKMeans
196
197# Custom kwargs for aeon.clustering.TimeSeriesKMeans
198model_kw = {
199 "distance" : "msm",
200 "distance_params" : {"window": 0.2},
201}
202
203scaler = StandardScaler()
204
205fig_title = "Time-series data using ts_dist (MSM) with TimeSeriesKMeans"
206fig_name = "full-UCR_data_MSM_TimeSeriesKMeans"
207
208pipeline(X, y, model_class, model_kw, k_max, scaler, ts_dist, fig_title, fig_name)
209
210
211# ==========================
212# PyCVI not using a time series distance
213# ==========================
214
215ts_dist = False
216
217model_class = KMeans
218model_kw = {}
219scaler = StandardScaler()
220fig_title = "Time-series data without ts_dist with KMeans"
221fig_name = "full-UCR_data_no_MSM_KMeans"
222
223pipeline(X, y, model_class, model_kw, k_max, scaler, ts_dist, fig_title, fig_name)
224
***** Non time-series data with KMeans *****
Clusterings generated in: 0.14s
================ VI ================
0 1.5095732725667173
1 1.5095732725667173
2 2.148777695494655
3 2.5230352737530968
4 2.7206717147127244
5 2.1721655832074562
6 2.505373693560177
7 2.0381172791972375
8 1.8693520544687843
9 1.998202851545777
====== Hartigan_monotonous ======
0 232.06549348253276
1 117.85431690122883
2 119.0578994223934
3 76.33944253775198
4 93.08873759080173
5 57.56880365900144
6 56.0763699998555
7 58.68913517891718
8 54.88254243248152
9 None
Code executed in 0.00 s
Selected k: 1 | True k: 3
====== CalinskiHarabasz_original ======
0 None
1 0.0
2 117.85431690122877
3 141.87973289450494
4 144.10760904513043
5 165.09192794645048
6 168.9996918173655
7 176.65208913786796
8 189.71483617478674
9 203.5980090668846
Code executed in 0.00 s
Selected k: 9 | True k: 3
====== GapStatistic_original ======
0 None
1 -0.004049261254301939
2 -0.14073624033767107
3 -0.26939419594791847
4 -0.49277760818549066
5 -0.4171698862436397
6 -0.44117786041608387
7 -0.4035386067712481
8 -0.4067638565878755
9 -0.3321428207811752
Code executed in 0.11 s
Selected k: 1 | True k: 3
====== Silhouette ======
0 None
1 None
2 0.2921126066668147
3 0.3200155274988587
4 0.30420420454162733
5 0.3690747100654749
6 0.36999919904481365
7 0.40770007892164983
8 0.4243611974654775
9 0.45209614052285363
Code executed in 0.12 s
Selected k: 9 | True k: 3
====== ScoreFunction ======
0 None
1 0.12657698150688346
2 0.06930297895304649
3 0.060391297863766735
4 0.04083376170587705
5 0.02761365518978609
6 0.03382223996577072
7 0.03201095406225185
8 0.028785506097609104
9 0.04708779292800236
Code executed in 0.00 s
Selected k: 1 | True k: 3
====== MaulikBandyopadhyay_absolute ======
0 None
1 0.0
2 0.8226342937096717
3 0.8274000904168224
4 1.069288371133994
5 1.222987931709547
6 0.9640513526747609
7 1.2702466648263546
8 1.2312670212661359
9 1.251886604921287
Code executed in 0.00 s
Selected k: 7 | True k: 3
====== SD ======
0 None
1 None
2 662.0498245526342
3 450.1212780231439
4 383.56364396918997
5 362.6622761745039
6 282.04683465402496
7 255.6869584781537
8 232.48949652756005
9 175.5880239931847
Code executed in 0.03 s
Selected k: 9 | True k: 3
====== SDbw ======
0 None
1 None
2 1.7995164960068868
3 2.181089389118835
4 inf
5 1.3030053687528433
6 inf
7 0.48169876414912477
8 0.3181701577704991
9 0.23407069696401947
Code executed in 0.01 s
Selected k: 9 | True k: 3
====== Dunn ======
0 None
1 None
2 0.007324042553335538
3 0.020686168390910403
4 0.015535065523201108
5 0.01578013340417025
6 0.023716458849230147
7 0.04390462708032294
8 0.03332063851588541
9 0.03482090688752006
Code executed in 0.00 s
Selected k: 7 | True k: 3
====== XB ======
0 None
1 None
2 0.5609467731673681
3 0.3615506512138411
4 0.35325360794722155
5 0.2652071100309934
6 0.24486576572750537
7 0.44354726412853474
8 0.39915507106184095
9 0.36135674245128513
Code executed in 0.00 s
Selected k: 6 | True k: 3
====== XB_star ======
0 None
1 None
2 0.6034729504505948
3 0.3838876026314225
4 0.4465843070861975
5 0.46285365172114423
6 0.32903260016918817
7 0.7256845429322208
8 0.7429495614084739
9 0.5673601488909971
Code executed in 0.00 s
Selected k: 6 | True k: 3
====== DB ======
0 None
1 None
2 1.511394153455492
3 1.1975719755356133
4 1.2050739216424151
5 0.9826146424985689
6 1.0721813288988526
7 1.061688059070726
8 1.0402772554925785
9 1.0879375122670034
Code executed in 0.00 s
Selected k: 5 | True k: 3
====== Inertia_sum ======
0 524.0762519879294
1 349.0214135130419
2 307.3995736857927
3 266.48148190125306
4 242.71478664395394
5 209.69704338571205
6 196.03790622871185
7 176.61176561681702
8 157.64205327057942
9 147.76657712086873
Code executed in 0.00 s
Selected k: 1 | True k: 3
====== Diameter_max ======
0 6.225889127666499
1 4.737154354950527
2 4.687181441144579
3 3.8435782753171948
4 3.4159742272348237
5 3.176692177193714
6 2.514479745113182
7 2.7537248149948876
8 2.5259159014354746
9 2.136467053014759
Code executed in 0.00 s
Selected k: 1 | True k: 3
***** Non time-series data with AgglomerativeClustering-Single *****
Clusterings generated in: 0.01s
================ VI ================
0 1.5095732725667173
1 1.5095732725667173
2 0.5935232483446198
3 0.0
4 0.17642364963340507
5 0.3160403254013091
6 0.35617410466552313
7 0.5092833003363406
8 0.6811955126547553
9 0.7159856910848794
====== Hartigan_monotonous ======
0 243.17059353383985
1 0.017211966847463733
2 0.011381644034187843
3 34.58290182504763
4 35.42587757523952
5 1.2950951116888347
6 60.33785949064855
7 114.59147910894787
8 1.8539186101937388
9 None
Code executed in 0.01 s
Selected k: 1 | True k: 3
====== CalinskiHarabasz_original ======
0 None
1 0.0
2 0.01721196684745756
3 0.0142681588644381
4 11.538225250696613
5 18.520003238398484
6 15.089892803326249
7 25.17787001256915
8 46.34652110326673
9 40.90394626337436
Code executed in 0.00 s
Selected k: 8 | True k: 3
====== GapStatistic_original ======
0 None
1 -0.006801696816472358
2 -0.4745749290602044
3 -0.9649979572777214
4 -1.3127589147998506
5 -1.3610920610306287
6 -1.5364962920413041
7 -1.5427186173689704
8 -1.3825724586738488
9 -1.475784748549298
Code executed in 0.11 s
Selected k: 1 | True k: 3
====== Silhouette ======
0 None
1 None
2 0.19510829001256025
3 0.12276877018507622
4 0.2666718402395447
5 0.31348555456323224
6 0.36558953430010227
7 0.3731558417803549
8 0.4027680246588693
9 0.4166374121873863
Code executed in 0.12 s
Selected k: 9 | True k: 3
====== ScoreFunction ======
0 None
1 0.12657698150688346
2 0.004135311875640868
3 0.0032293485050610693
4 0.0029632576876932326
5 0.003264097402863153
6 0.0037227535316397553
7 0.0049664095832882005
8 0.010149481944074723
9 0.011314974675989298
Code executed in 0.00 s
Selected k: 1 | True k: 3
====== MaulikBandyopadhyay_absolute ======
0 None
1 0.0
2 0.00013083550172281476
3 8.475580765301406e-05
4 0.427718738217691
5 0.37675811580288987
6 0.2736495991736414
7 0.3198667973300651
8 0.5148041633787491
9 0.4148452726415676
Code executed in 0.00 s
Selected k: 8 | True k: 3
====== SD ======
0 None
1 None
2 1235.2412717775123
3 895.0734489387124
4 760.3737998020256
5 586.6586545582198
6 480.8898870658816
7 427.8769607892363
8 366.0067509925373
9 327.9051238357357
Code executed in 0.03 s
Selected k: 9 | True k: 3
====== SDbw ======
0 None
1 None
2 2.361153676117582
3 inf
4 inf
5 inf
6 inf
7 inf
8 inf
9 inf
Code executed in 0.01 s
Selected k: 2 | True k: 3
====== Dunn ======
0 None
1 None
2 0.22248894960242496
3 0.09930825342423276
4 0.07694370083375403
5 0.06829859591450839
6 0.06533380025087833
7 0.06397229612167823
8 0.060820685569083446
9 0.06081222025210591
Code executed in 0.00 s
Selected k: 2 | True k: 3
====== XB ======
0 None
1 None
2 3821.6310955892613
3 5646.56635055878
4 3300.5590447734985
5 2945.6227492079197
6 2932.660040393725
7 2430.441999712767
8 1743.7709082799424
9 1732.6941019304872
Code executed in 0.00 s
Selected k: 9 | True k: 3
====== XB_star ======
0 None
1 None
2 9446.229005417188
3 13957.603039842359
4 8989.974686370095
5 8641.081615403013
6 8641.081615403013
7 7751.014168430339
8 5854.809633100443
9 5854.809633100443
Code executed in 0.00 s
Selected k: 8 | True k: 3
====== DB ======
0 None
1 None
2 129.40126293281918
3 125.11207732852509
4 43.39706303619012
5 43.39706303619012
6 43.39706303619011
7 43.39706303619011
8 43.39706303619012
9 43.39706303619011
Code executed in 0.00 s
Selected k: 6 | True k: 3
====== Inertia_sum ======
0 534.4874209327967
1 349.0214135130419
2 349.0095479285938
3 349.0536409924574
4 325.43055668310694
5 303.72575042981157
6 300.60978707111775
7 272.065674157918
8 233.85530390170882
9 231.56485922473567
Code executed in 0.00 s
Selected k: 1 | True k: 3
====== Diameter_max ======
0 6.141355878094843
1 4.737154354950527
2 4.737154354950527
3 4.737154354950527
4 4.737154354950527
5 4.737154354950527
6 4.737154354950527
7 4.737154354950527
8 4.665215171139693
9 4.665215171139693
Code executed in 0.00 s
Selected k: 1 | True k: 3
***** Time-series data using ts_dist (MSM) with TimeSeriesKMeans *****
Clusterings generated in: 136.18s
================ VI ================
0 1.9826631670014707
1 1.9826631670014707
2 0.9862725476337011
3 1.4993024282502483
4 1.9524232138516764
5 2.2522495749194937
6 2.283830650440789
7 2.502019331976564
8 2.5535376463472206
9 2.412253216914125
====== Hartigan_monotonous ======
0 44.82395258134479
1 271.13833176062394
2 64.65676360724547
3 64.70935819258743
4 24.00067046202492
5 27.69482494863435
6 15.369600900952461
7 7.527206988213957
8 30.9988409227118
9 None
Code executed in 28.76 s
Selected k: 2 | True k: 4
====== CalinskiHarabasz_original ======
0 None
1 0.0
2 559.4086836804266
3 489.88699135236993
4 480.6691574679418
5 446.4554305183199
6 451.44479417788597
7 432.75205332847423
8 395.2799274397586
9 464.34594295972653
Code executed in 16.12 s
Selected k: 2 | True k: 4
====== GapStatistic_original ======
0 None
1 0.3805844469596007
2 1.7011804546031577
3 2.2077711810274607
4 2.7148481706089047
5 2.930185188313107
6 3.179913676796925
7 3.3214332730609843
8 3.3907692240664993
9 3.6749176783806643
Code executed in 131.00 s
Selected k: None | True k: 4
====== Silhouette ======
0 None
1 None
2 0.6485114553580815
3 0.5986822875271275
4 0.5162205993003215
5 0.49101499104963375
6 0.46723460735999983
7 0.4619040798337992
8 0.4977836763129246
9 0.46911860682207834
Code executed in 18.10 s
Selected k: 2 | True k: 4
====== ScoreFunction ======
0 None
1 0.0
2 1.0
3 1.0
4 0.0
5 0.0
6 0.0
7 0.0
8 0.0
9 0.0
Code executed in 19.70 s
Selected k: 2 | True k: 4
====== MaulikBandyopadhyay_absolute ======
0 None
1 0.0
2 54381.090895915346
3 50553.90311005585
4 46470.226102301654
5 41105.351094128084
6 40622.36415754344
7 36595.61263376264
8 33698.075489538955
9 30155.13793582499
Code executed in 16.43 s
Selected k: 2 | True k: 4
====== SD ======
0 None
1 None
2 0.05356167024291173
3 0.04309266821745296
4 0.040982526671671
5 0.042219842843900665
6 0.04050983673596388
7 0.04992521867797746
8 0.05457048564486449
9 0.04902103646207711
Code executed in 46.29 s
Selected k: 6 | True k: 4
====== SDbw ======
0 None
1 None
2 0.17442086058270134
3 0.11470220138335113
4 inf
5 inf
6 0.03870474871020616
7 0.030826566035482166
8 inf
9 inf
Code executed in 23.84 s
Selected k: 7 | True k: 4
====== Dunn ======
0 None
1 None
2 0.8235232934630395
3 0.07276372021262471
4 0.11371123757135405
5 0.10253742781880605
6 0.12174812088033725
7 0.11144568738232707
8 0.11144568738232707
9 0.16159603622710797
Code executed in 9.04 s
Selected k: 2 | True k: 4
====== XB ======
0 None
1 None
2 0.07729899978682377
3 0.2138826717451771
4 0.19868103064490739
5 0.2262512909285799
6 0.18352413566812667
7 0.28856423774066864
8 0.33927070408341786
9 0.22629039161764514
Code executed in 6.61 s
Selected k: 2 | True k: 4
====== XB_star ======
0 None
1 None
2 0.07895670501519059
3 0.346750593722074
4 0.2579471012509385
5 0.36362466666786536
6 0.34227812852021383
7 0.6227178868262979
8 0.786097733935835
9 0.4174242701779115
Code executed in 6.67 s
Selected k: 2 | True k: 4
====== DB ======
0 None
1 None
2 0.5555629952382906
3 0.6275447998741295
4 0.9929945087783661
5 0.9929945087783661
6 0.8345488343417881
7 0.8345488343417881
8 0.8345488343417881
9 1.0193628924989935
Code executed in 6.58 s
Selected k: 2 | True k: 4
====== Inertia_sum ======
0 16372.716526290325
1 11756.551067446275
2 5309.999080718087
3 4002.651305572027
4 3221.168130120865
5 2823.224284441372
6 2465.8966130327854
7 2232.2653130309036
8 2121.6604787201154
9 1916.8483355104204
Code executed in 21.71 s
Selected k: 2 | True k: 4
====== Diameter_max ======
0 209.23063247403064
1 281.0189505183936
2 177.08071849410624
3 176.56648114304892
4 112.98473490589328
5 112.98473490589328
6 95.15682062499096
7 95.15682062499096
8 95.15682062499096
9 68.07523142085509
Code executed in 15.51 s
Selected k: 4 | True k: 4
***** Time-series data without ts_dist with KMeans *****
Clusterings generated in: 0.17s
================ VI ================
0 1.9826631670014707
1 1.9826631670014707
2 0.9862725476337011
3 1.4393933332351287
4 1.9524232138516764
5 2.1456525933667088
6 2.372492287411151
7 2.398931193847721
8 2.744988281048764
9 2.735982652514835
====== Hartigan_monotonous ======
0 16.44418491910634
1 180.2820962759362
2 53.846852033119156
3 22.394820456074363
4 25.202760282907153
5 21.309513200043543
6 15.277152546441965
7 10.159604081523373
8 11.824396225980948
9 None
Code executed in 0.01 s
Selected k: 2 | True k: 4
====== CalinskiHarabasz_original ======
0 None
1 0.0
2 180.28209627593617
3 166.17448068089334
4 142.93732434587815
5 140.8153501455836
6 141.25368243775634
7 138.32838598553474
8 131.82321759735586
9 130.5436220322559
Code executed in 0.01 s
Selected k: 2 | True k: 4
====== GapStatistic_original ======
0 None
1 0.14959122676002323
2 1.1839927860183597
3 1.6105113329816136
4 1.801163247512756
5 2.0278876619618753
6 2.21784351480873
7 2.3615593351505177
8 2.4442422907963746
9 2.552632292986827
Code executed in 0.19 s
Selected k: None | True k: 4
====== Silhouette ======
0 None
1 None
2 0.5851724720291331
3 0.5053323519853271
4 0.4602712659960852
5 0.45701901067637046
6 0.41519039685198805
7 0.42845540182332315
8 0.40574905162709773
9 0.41244505069255855
Code executed in 0.05 s
Selected k: 2 | True k: 4
====== ScoreFunction ======
0 None
1 0.0
2 0.0
3 0.0
4 0.0
5 0.0
6 0.0
7 0.0
8 0.0
9 0.0
Code executed in 0.01 s
Selected k: 1 | True k: 4
====== MaulikBandyopadhyay_absolute ======
0 None
1 0.0
2 465.6343632128651
3 378.23916578603587
4 323.65402363440177
5 266.4697539400852
6 227.57932618095361
7 190.35145971623214
8 180.30771550248988
9 162.08117920277968
Code executed in 0.01 s
Selected k: 2 | True k: 4
====== SD ======
0 None
1 None
2 1.529704442763962
3 1.6322356854720357
4 1.3340022170871626
5 1.2712656221929055
6 1.3534362780542557
7 1.4051561538550463
8 1.31702654127298
9 1.3054141636717387
Code executed in 0.08 s
Selected k: 5 | True k: 4
====== SDbw ======
0 None
1 None
2 inf
3 inf
4 inf
5 inf
6 inf
7 inf
8 inf
9 inf
Code executed in 0.12 s
Selected k: None | True k: 4
====== Dunn ======
0 None
1 None
2 0.6502295327816004
3 0.4183330532684955
4 0.05453741885973551
5 0.05453741885973551
6 0.06321374469697073
7 0.07400800378311924
8 0.10630220241347883
9 0.07265688453848344
Code executed in 0.01 s
Selected k: 2 | True k: 4
====== XB ======
0 None
1 None
2 0.133838927267939
3 0.2070968818131891
4 0.5675473082510522
5 0.44755211078152235
6 0.36411970567875473
7 0.31226605225137
8 0.5271812557624344
9 0.4123248861804025
Code executed in 0.01 s
Selected k: 2 | True k: 4
====== XB_star ======
0 None
1 None
2 0.23315333559033175
3 0.3264007671262031
4 1.1053632201735628
5 1.1053632201735628
6 0.9130044140189886
7 0.715292887528786
8 1.342408899772256
9 1.1878832113584739
Code executed in 0.01 s
Selected k: 2 | True k: 4
====== DB ======
0 None
1 None
2 0.7011289065432457
3 1.1189101040092817
4 1.1189101040092817
5 1.0398228359696284
6 1.4226602670081683
7 1.069681854739743
8 1.2474667583315489
9 1.2262026392098044
Code executed in 0.01 s
Selected k: 2 | True k: 4
====== Inertia_sum ======
0 1550.7100623367241
1 1411.2211210804048
2 766.9830051666322
3 633.3155315412099
4 525.9256968224321
5 463.69340900804167
6 429.2586106174678
7 406.28201524121323
8 368.9581820049782
9 347.87687380455446
Code executed in 0.00 s
Selected k: 2 | True k: 4
====== Diameter_max ======
0 26.52376778327575
1 29.63943217185524
2 26.085661705315456
3 21.104625863172615
4 21.104625863172615
5 21.104625863172615
6 18.207936044532552
7 15.55226140068361
8 15.55226140068361
9 14.509602898389424
Code executed in 0.01 s
Selected k: 3 | True k: 4