partition based clustering we will choose the simplest yet most popular partition based clustering model for our examplewhich is -means algorithm this algorithm is centroid based clustering algorithmwhich starts with some assumption about the total clusters in the data and with random centers assigned to each of the clusters it then reassigns each data point to the center closest to itusing euclidean distance as the distance metric after each reassignmentit recalculates the center of that cluster the whole process is repeated iteratively and stopped when reassignment of data points doesn' change the cluster centers variants include algorithms like -medoids since we already know from the data labels that we have two possible types of categories either or the following code tries to determine these two clusters from the data by leveraging -means clustering in the real worldthis is not always the casesince we will not know the possible number of clusters this is one of the most important downsides of -means clustering from sklearn cluster import kmeans km kmeans(n_clusters= km fit(xlabels km labels_ centers km cluster_centers_ print(labels[: ][ once the fit process is complete we can get the centers and labels of our two clusters in the dataset by using the preceding attributes the centers here refer to some numerical value of the dimensions of the data (the attributes in the datasetaround which data is clustered but can we visualize and compare the clusters with the actual labelsremember we are dealing with features and visualizing the clusters on -dimensional feature space would be impossible to interpret or even perform hencewe will leverage pca to reduce the input dimensions to two principal components and visualize the clusters on top of the same refer to to learn more about principal component analysis from sklearn decomposition import pca pca pca(n_components= bc_pca pca fit_transform(xthe following code helps visualize the clusters on the reduced feature space for the actual labels as well as the clustered output labels fig(ax ax plt subplots( figsize=( )fig suptitle('visualizing breast cancer clusters'fig subplots_adjust(top= wspace= ax set_title('actual labels'ax set_title('clustered labels'for in range(len( ))if [ = ax scatter(bc_pca[ , ]bc_pca[ , ], =' 'marker='if [ = ax scatter(bc_pca[ , ]bc_pca[ , ], =' 'marker='