October 2019
Beginner to intermediate
674 pages
16h 43m
English
The idea behind clustering is to group together similar points in a dataset based on a given criterion, hence finding clusters in the data.
The K-means algorithm aims to partition a set of data points into K clusters such that each data point belongs to the cluster with the nearest mean point or centroid.
To illustrate K-means clustering, we can apply it to the set of reduced iris data that we obtained via PCA, but in this case, we do not pass the actual labels to the fit(..) method as we do for supervised learning:
In [142]: from sklearn.cluster import KMeans
k_means = KMeans(n_clusters=3, random_state=0)
k_means.fit(X_red)
y_pred = k_means.predict(X_red)
We now display the clustered data as follows:
In [145]: figsize(8,6) ...
Read now
Unlock full access