Skip to content

Instantly share code, notes, and snippets.

@aliakbars
Created November 12, 2017 09:22
Show Gist options
  • Save aliakbars/f677e8468162a4ca6aba931b16af8b11 to your computer and use it in GitHub Desktop.
Save aliakbars/f677e8468162a4ca6aba931b16af8b11 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_blobs
from sklearn.cluster import KMeans
# Anda dapat mengganti nilai X dan y sesuai dengan kebutuhan Anda
X, y = make_blobs(n_samples=300, centers=4,
cluster_std=1.2, random_state=3)
inertia = []
for k in range(1,11):
kmeans = KMeans(n_clusters=k)
kmeans.fit(X)
inertia.append(kmeans.inertia_)
plt.plot(range(1,11), inertia, c='orange', zorder=1)
plt.scatter(range(1,11), inertia, zorder=2)
plt.xlabel('$k$')
plt.ylabel('jarak agregat')
plt.savefig('scree.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment