text_plain_output_1.png image_output_1.png
from sklearn.cluster import KMeans

import matplotlib.pyplot as plt

import pandas as pd

data = pd.read_csv('../input/iris-dataset/iris.data.csv')

data.describe().T

X = data.iloc[:, [0, 1, 2, 3]].values

wcss = []
for i in range(1, 11):
    kmeans = KMeans(n_clusters=i, init='k-means++', max_iter=200, n_init=10, random_state=0)
    kmeans.fit(X)
    wcss.append(kmeans.inertia_)

plt.plot(range(1, 11), wcss)
plt.title('THE ELBOW METHOD')
plt.xlabel('Number of Clusters')
plt.ylabel('wcss')
plt.show()