Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.collection.JavaConversions._
- import org.apache.commons.math3.ml.clustering._
- val kmeans = new KMeansPlusPlusClusterer[DoublePoint](3)
- val points = (1 to 90).map{ x =>
- if (x< 30) new DoublePoint(Array(1+1.0/x, 1+1.0/x))
- else if (x<60) new DoublePoint(Array(10+ 1.0/x, 10+1.0/x))
- else new DoublePoint(Array(20+1.0/x, 20+1.0/x))
- }
- val centroids = kmeans.cluster(points.toIterable)
- centroids.map{ x=> x.getCenter.getPoint }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement