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

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/HarvinderSinghDiwan/DEEP_LEARNING_SESSION/blob/master/KMeans2.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="7Wo2XngMhyOk" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 282} outputId="368c1446-a556-4b52-d598-11b9fff59e0f"
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
x,y=make_blobs(n_samples=150,n_features=2,centers=3,cluster_std=0.5,shuffle=True,random_state=0)
plt.scatter(x[:,0],x[:,1],c='white',marker='o',edgecolor='black',s=50)

# + id="WYr-PYnCjTTl" colab_type="code" colab={}
from sklearn.cluster import KMeans
km=KMeans(n_clusters=3,init='random',n_init=10,max_iter=300,tol=1e-04,random_state=0)

# + id="L6eKWF53jyG6" colab_type="code" colab={}
y_km=km.fit_predict(x)

# + id="VygN45o1j3TL" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 265} outputId="b9e98952-2151-4a43-b986-50723f0c3469"
plt.scatter(x[y_km==0,0],x[y_km==0,1],s=50,c='lightgreen',marker='P',edgecolor='black',label='cluster 1')
plt.scatter(x[y_km==1,0],x[y_km==1,1],s=50,c='orange',marker='>',edgecolor='pink',label='cluster 2')
plt.scatter(x[y_km==2,0],x[y_km==2,1],s=50,c='',marker='*',edgecolor='red',label='cluster 3')
plt.scatter(km.cluster_centers_ [:,0],km.cluster_centers_ [:,1],s=250,marker='*',c='red',edgecolor='blue',label='centroid')
plt.legend(scatterpoints=1)
plt.grid()
plt.show()

# + id="VOZVcKBbo2kn" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered