How it works...

We read a LIBSVM file with a set of coordinates (can be interpreted as a tuple of three numbers) and then created a KMean() object, but changed the default number of clusters from 2 (out of the box) to 3 for demonstration purposes. We used the .fit() to create the model and then used model.summary.predictions.show() to display which tuple belongs to which cluster. In the last step, we printed the cost and the center of the three clusters. Conceptually, it can be thought of as having a set of 3D coordinates as data and then assigning each individual coordinate to one of the three clusters using KMeans algorithms.

KMeans is a form of unsupervised machine learning algorithm, with its root in signal processing (vector quantization) and compression (grouping similar vectors of items together to achieve a higher compression rate). Generally speaking, the KMeans algorithm attempts to group a series of observations {X1, X2, .... , Xn} into a series of clusters {C1, C2 ..... Cn} using a form of distance measure (local optimization) that is optimized in an iterative manner.

There are three main types of KMeans algorithm that are in use. In a simple survey, we found 12 specialized variations of the KMeans algorithm. It is important to note that Spark implements a version called KMeans || (KMeans Parallel) and not KMeans++ or standard KMeans as referenced in some literature or videos.

The following figure depicts KMeans in a nutshell:

Source: Spark documentation
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.167.196