Example Analysis of Gaussian mixture clustering in spark mlilib
This article mainly introduces the example analysis of Gaussian mixture clustering in spark mlilib, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
The running code is as follows: package spark.clusteringimport org.apache.spark.mllib.clustering. {GaussianMixture, KMeans} import org.apache.spark.mllib.linalg.Vectorsimport org.apache.spark. {SparkConf, SparkContext} / * * Gaussian mixture clustering * Gaussian distribution: when a data vector is within the model calculation of a Gaussian distribution, it is considered to match the Gaussian distribution. Clustering belonging to this model. * mixed Gaussian distribution: the clustering of any sample can be represented by multiple single Gaussian distribution models. * * Created by eric on 16-7-21. * / object GMG {val conf = new SparkConf () / / create the environment variable .setMaster ("local") / / set the localization handler .setAppName ("gaussian") / / set the name val sc = new SparkContext (conf) Def main (args: Array [String]) {val data = sc.textFile (". / src/main/spark/clustering/gmg.txt") val parsedData = data.map (s = > Vectors.dense (s.trim (). Split ('). Map (_ .toDouble)) .cache () val model = new GaussianMixture (). SetK (2) .run (parsedData) / / sets the number of classifications for the training model for (I)