In this example, we'll be plotting an elbow curve for our k-means clusterer on the Iris dataset. We'll first create an instance of KMeans
from scikit-learn, and then feed that to our scikitplot.cluster.plot_elbow_curve
method.
In [1]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import load_iris as load_data
# Import scikit-plot
import scikitplot as skplt
%pylab inline
pylab.rcParams['figure.figsize'] = (14, 14)
In [2]:
# Load the data
X, y = load_data(return_X_y=True)
# Create clusterer instance
kmeans = KMeans(random_state=1)
In [3]:
# Plot!
skplt.cluster.plot_elbow_curve(kmeans, X, cluster_ranges=range(1, 11))
plt.show()
In [ ]: