# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

plt.figure(figsize = (16,9))
plt.rcParams['figure.dpi'] = 150 

# +
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs

# create dataset
X, y = make_blobs(
   n_samples=150, n_features=2,
   centers=3, cluster_std=0.5,
   shuffle=True, random_state=0
)

# plot
plt.scatter(
   X[:, 0], X[:, 1],
   edgecolor='black', s=50
)
plt.show()

# +
from sklearn.cluster import KMeans

km = KMeans(
    n_clusters=3, init='random',
    n_init=1, max_iter=2, 
    tol=1e-04, random_state=0
)
y_km = km.fit_predict(X)
y_km
# -

plt.scatter(X[:,0], X[:,1], c=y_km, cmap=plt.cm.Paired, alpha=0.4)
plt.scatter(km.cluster_centers_[:, 0],km.cluster_centers_[:, 1], 
            s=250, marker='*', label='centroids',
            edgecolor='black',
           c=[0,1,2],cmap=plt.cm.Paired,)

XC= X.transpose() # nice alternative
plt.scatter(XC[0], XC[1],c=y_km, cmap=plt.cm.Paired, alpha=0.4)

# +
# plot the 3 clusters
#plt.grid()

plt.scatter(
    X[y_km == 0, 0], X[y_km == 0, 1],
    s=50, c='lightgreen',
    label='cluster 1'
)

plt.scatter(
    X[y_km == 1, 0], X[y_km == 1, 1],
    s=50, c='orange',
    marker='o', edgecolor='black',
    label='cluster 2'
)

plt.scatter(
    X[y_km == 2, 0], X[y_km == 2, 1],
    s=50, c='lightblue',
    label='cluster 3'
)

# plot the centroids
plt.scatter(
    km.cluster_centers_[:, 0], km.cluster_centers_[:, 1],
    s=250, marker='*',
    label='centroids'
)
plt.legend(scatterpoints=1)
plt.show()
# -



StarcoderdataJupyterScriptsDedupFiltered