Actually there is a problem to find X-means on Ruby. This library is awesome because can be adjusted easily. You can redefine calcAverage, calcSum, calcDistanceSquared functions for your needs.https://github.com/vaneyckt/kmeans-clustering/blob/master/example.rb