watex.utils.plot_clusters#
- watex.utils.plot_clusters(n_clusters, X, y_pred, cluster_centers=None, savefig=None)[source]#
Visualize the cluster that k-means identified in the dataset
- Parameters
n_clusters – int, number of cluster to visualize
X – NDArray, data containing the features, expect to be a two dimensional data
y_pred – array-like, array containing the predicted class labels.
cluster_centers – NDArray containg the coordinates of the centroids or the similar points with continous features.
- Example
>>> from watex.exlib.sklearn import KMeans, MinMaxScaler >>> from watex.utils.plotutils import plot_clusters >>> from watex.datasets import fetch_data >>> h= fetch_data('hlogs').frame >>> # collect two features 'resistivity' and gamma-gamma logging values >>> h2 = h[['resistivity', 'gamma_gamma']] >>> km = KMeans (n_clusters =3 , init= 'random' ) >>> # scaled the data with MinMax scaler i.e. between ( 0-1) >>> h2_scaled = MinMaxScaler().fit_transform(h2) >>> ykm = km.fit_predict(h2_scaled ) >>> plot_clusters (3 , h2_scaled, ykm , km.cluster_centers_ )