Skip to content

Instantly share code, notes, and snippets.

View ishankhatri90's full-sized avatar
🎯
Focusing

Ishan Khatri ishankhatri90

🎯
Focusing
  • Houston
View GitHub Profile
@ishankhatri90
ishankhatri90 / kMeans.py
Created September 23, 2016 17:26 — forked from bistaumanga/kMeans.py
KMeans Clustering Implemented in python with numpy
'''Implementation and of K Means Clustering
Requires : python 2.7.x, Numpy 1.7.1+'''
import numpy as np
def kMeans(X, K, maxIters = 10, plot_progress = None):
centroids = X[np.random.choice(np.arange(len(X)), K), :]
for i in range(maxIters):
# Cluster Assignment step
C = np.array([np.argmin([np.dot(x_i-y_k, x_i-y_k) for y_k in centroids]) for x_i in X])