As a final project for one of my data analytics courses, I was required
to create a K Means clustering algorithm from scratch. For those who
don't know what a K Means algorithm is, consider vectors of 10+
dimensions that require grouping based on similarity. There is almost
no way to visualize such a nebulous object, but linear algebra holds
the solution.

K Means takes your data frame of vectors, selects a random "centroid"
(or in this case, 3)—a point around which items will cluster—and
measures each vector's Euclidean distance from the randomly selected
vector. A data point is assigned to the cluster to which it is nearest.
Each iteration of the "for loop" refines the location of the clusters
and by the "break," the vectors have been assigned to their nearest
grouping of similar vectors.

This data set was a collection of wines grown in the same region in
Italy by three separate cultivars. Each wine contained 13 dimensions:
alcoholic content, malic acid, ash, alkalinity of ash, magnesium, total
phenols, flavanoids, nonflavanoid phenols, proanthocyanins, color
intensity, hue, OD280/OD315 of diluted wines and proline. Each
13-dimensional vector represented a wine, and was compared against its
companion vectors in an attempt to correctly classify the cultivars
from which each wine originated. The outcome of the script—though
slightly different each run, per K means’ initially random centroid
selection method—indicates an average of 95.6% clustering accuracy.