Crude working version of K-means clustering

Promoted code from script to module
Added minimal tests
Test script seems to be behaving properly