Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- """!
- The pyclustering library clarans implementation requires
- list of lists as its input dataset.
- Thus we convert the data from numpy array to list.
- """
- data = data.tolist()
- #get a glimpse of dataset
- print("A peek into the dataset : ",data[:4])
- """!
- @brief Constructor of clustering algorithm CLARANS.
- @details The higher the value of maxneighbor, the closer is CLARANS to K-Medoids, and the longer is each search of a local minima.
- @param[in] data: Input data that is presented as list of points (objects), each point should be represented by list or tuple.
- @param[in] number_clusters: amount of clusters that should be allocated.
- @param[in] numlocal: the number of local minima obtained (amount of iterations for solving the problem).
- @param[in] maxneighbor: the maximum number of neighbors examined.
- """
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement