Find file History
Latest commit 3b89d57 Dec 24, 2018
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md Add K-Means. Dec 21, 2018
__init__.py Fixing Pylint errors. Dec 23, 2018
k_means.py Fixing Pylint errors. Dec 24, 2018

README.md

K-Means Algorithm

Jupyter Demos

▶️ Demo | K-means Algorithm - split Iris flowers into clusters based on petal_length and petal_width

Definition

K-means clustering aims to partition n observations into K clusters in which each observation belongs to the cluster with the nearest mean, serving as a prototype of the cluster.

The result of a cluster analysis shown below as the coloring of the squares into three clusters.

Clustering

Description

Given a training set of observations:

Training set

x-i

Where each observation is a d-dimensional real vector, k-means clustering aims to partition the m observations into K (≤ m) clusters:

Clusters

... so as to minimize the within-cluster sum of squares (i.e. variance).

Below you may find an example of 4 random cluster centroids initialization and further clusters convergence:

Clustering

Picture Source

Another illustration of k-means convergence:

Clustering

Cost Function (Distortion)

c-i - index of cluster (1, 2, ..., K) to which example x(i) is currently assigned.

mu-k - cluster centroid k (mu-k-2) and k.

mu-c-i - cluster centroid of a cluster to which the example x(i) has been assigned.

For example:

Cluster example

In this case optimization objective will look like the following:

Cost Function

Clustering

The Algorithm

Randomly initialize K cluster centroids (randomly pick K training examples and set K cluster centroids to that examples).

Centroids

k-means-algorithm

References