Package: clusterval
clustervalFor validating clustering resultsMotivationThis package was made to facilitate the process of clustering of a dataset. The user needs only to specifiy the dataset or the pairwise distances
in the form of a list-like structure and clustering will be performed as well as evaluation of the results, through the
use of CVIs (Clustering Validation Indices).clustervaloutputs the best partition of the data, a dendrogram andk,
the number of clusters. Clustering algorithms available are: 'single', 'complete', 'ward', 'centroid', 'average' and 'kmeans.InstallationYou can get the stable version from PyPI:pip install clustervalOr the development version from GitHub:pip install git+https://github.com/Nuno09/clusterval.gitBasic usage1.Load libraries.fromclustervalimportClustervalfromsklearn.datasetsimportload_iris,make_blobs2.Let's use the iris datasetdata=load_iris()['data']3.Useclustervalto determine the optimal number of clusters. The code below will create a Clusterval
object that for an input dataset will partition the data
into 2-8 clusters using hierarchical aglomerative clustering, with ward criteria, then calculate various CVIs across the
results.c=Clusterval()c.evaluate(data)Outupt:Clusterval(min_k=2,max_k=8,algorithm=ward,bootstrap_samples=250,index=['all'])final_k=24.If user wishes more information on the resulting clustering just type below command.print(c.long_info)Longoutput:*Minimumnumberofclusterstotest:2*Maximumnumberofclusterstotest:8*Numberofbootstrapsamplesgenerated:250*Clusteringalgorithmused:ward*ValidationIndicescalculated:['AR','FM','J','AW','VD','H','F','VI','K','Phi','RT','SS','CVNN','XB','SDbw','DB','S','SD','PBM','Dunn']*Amongallindices:*Accordingtothemajorityrule,thebestnumberofclustersis2*15proposed2asthebestnumberofclusters*3proposed3asthebestnumberofclusters*1proposed6asthebestnumberofclusters*1proposed8asthebestnumberofclusters*****Conclusion*****ARFMJAWVDHFVIKPhiRTSSCVNNXBSDbwDBSSDPBM\20.9994260.5267380.3569550.0003310.3859820.0002830.5260451.3123830.5274332.974318e-060.3336110.2172911.0000000.2615390.7524600.1913760.72223410.71433120.48522031.0001720.3792440.233104-0.0007910.525643-0.0008910.3780011.9723550.380492-9.809481e-060.3569570.1319540.9741220.4143860.7916270.3888190.56039210.76461525.47360841.0000800.2855000.166032-0.0006070.586732-0.0006770.2846662.5111330.286337-8.672063e-060.4183380.0905621.2334810.6103470.7989490.4489810.45840912.50030419.11193251.0000700.2638340.150461-0.0008150.591750-0.0009720.2614702.6768280.266223-1.296032e-050.4345580.0813741.5528750.5789000.6999640.5275330.43609315.18808518.93220061.0000420.1928720.106553-0.0000790.675911-0.0000650.1925123.0961660.193233-8.572647e-070.5243170.0562891.5180290.7678590.6950730.5809750.36710918.29795616.65717771.0000360.1704230.092730-0.0015020.687232-0.0016260.1696473.2460900.171204-2.903045e-050.5546760.0486331.4791090.8844220.7431850.7373070.33552821.94217413.61941181.0000320.1550100.083478-0.0004460.694161-0.0004960.1540143.3491530.156014-9.595088e-060.5814930.0435711.4555320.8844220.7012680.6816910.37014622.22919611.636157Dunn20.33890930.11279540.12350850.12350860.13108170.13108180.150756*Thebestpartitionis:[000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111]4.It's also possible to visualize the hierarchical clustering.
Note: in linux systems installation of library "python3-tk" might be needed.c.plot()5.The user can also change some execution parameters. For example, clustering algorithm, range ofkto test,
bootstrap simulations and CVI to use.data,_=make_blobs(n_samples=700,centers=10,n_features=5,random_state=0)c=Clusterval(min_k=5,max_k=15,algorithm='kmeans',bootstrap_samples=200,index='CVNN')c.evaluate(data)Output:Clusterval(min_k=5,max_k=15,algorithm=kmeans,bootstrap_samples=200,index=['CVNN'])final_k=10