Skip to content

Instantly share code, notes, and snippets.

View csu1505110121's full-sized avatar

Qiang Zhu csu1505110121

View GitHub Profile
@csu1505110121
csu1505110121 / kMeans.py
Created July 18, 2017 15:28 — 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])