example let us move to another example in which we are going to apply -means clustering on simple digits dataset -means will try to identify similar digits without using the original label information firstwe will start by importing the necessary packages%matplotlib inline import matplotlib pyplot as plt import seaborn as snssns set(import numpy as np from sklearn cluster import kmeans nextload the digit dataset from sklearn and make an object of it we can also find number of rows and columns in this dataset as followsfrom sklearn datasets import load_digits digits load_digits(digits data shape output ( the above output shows that this dataset is having samples with features we can perform the clustering as we did in example abovekmeans kmeans(n_clusters= random_state= clusters kmeans fit_predict(digits datakmeans cluster_centers_ shape output ( the above output shows that -means created clusters with features figax plt subplots( figsize=( )centers kmeans cluster_centers_ reshape( for axicenter in zip(ax flatcenters)axi set(xticks=[]yticks=[]axi imshow(centerinterpolation='nearest'cmap=plt cm binary