Claran Clustering Algorithm || Python
In this we are going to see a basic example of Claran clustering algorithm in Python Programming Language.



# pip install pyclustering sklearn

from pyclustering.cluster.clarans import clarans
from pyclustering.utils import timedcall
from sklearn import datasets


#import iris dataset from sklearn library
iris = datasets.load_iris()


#get the iris data. It has 4 features, 3 classes and 150 data points.
data = iris.data


data = data.tolist()


#get a glimpse of dataset
print("A peek into the dataset : ", data[:4])
clarans_instance = clarans(data, 3, 6, 4)


#calls the clarans method 'process' to implement the algortihm
(ticks, result) = timedcall(clarans_instance.process)
print("Execution time : ", ticks, "\n")


#returns the clusters
clusters = clarans_instance.get_clusters()


#returns the mediods
medoids = clarans_instance.get_medoids()



print("Index of the points that are in a cluster : ", clusters)
print("The target class of each datapoint : ", iris.target)
print("The index of medoids that algorithm found to be best : ", medoids)



#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post