Class KMeansModel
Object
org.apache.spark.mllib.clustering.KMeansModel
- All Implemented Interfaces:
Serializable
,PMMLExportable
,Saveable
- Direct Known Subclasses:
StreamingKMeansModel
A clustering model for K-means. Each point belongs to the cluster with the closest center.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
-
Constructor Summary
ConstructorDescriptionKMeansModel
(Iterable<Vector> centers) A Java-friendly constructor that takes an Iterable of Vectors.KMeansModel
(Vector[] clusterCenters) KMeansModel
(Vector[] clusterCenters, String distanceMeasure, double trainingCost, int numIter) -
Method Summary
Modifier and TypeMethodDescriptionVector[]
double
computeCost
(RDD<Vector> data) Return the K-means cost (sum of squared distances of points to their nearest center) for this model on the given data.int
k()
Total number of clusters.static KMeansModel
load
(SparkContext sc, String path) Maps given points to their cluster indices.int
Returns the cluster index that a given point belongs to.Maps given points to their cluster indices.void
save
(SparkContext sc, String path) Save this model to the given path.double
-
Constructor Details
-
KMeansModel
-
KMeansModel
-
KMeansModel
A Java-friendly constructor that takes an Iterable of Vectors.- Parameters:
centers
- (undocumented)
-
-
Method Details
-
load
-
clusterCenters
-
distanceMeasure
-
trainingCost
public double trainingCost() -
k
public int k()Total number of clusters.- Returns:
- (undocumented)
-
predict
Returns the cluster index that a given point belongs to.- Parameters:
point
- (undocumented)- Returns:
- (undocumented)
-
predict
Maps given points to their cluster indices.- Parameters:
points
- (undocumented)- Returns:
- (undocumented)
-
predict
Maps given points to their cluster indices.- Parameters:
points
- (undocumented)- Returns:
- (undocumented)
-
computeCost
Return the K-means cost (sum of squared distances of points to their nearest center) for this model on the given data.- Parameters:
data
- (undocumented)- Returns:
- (undocumented)
-
save
Description copied from interface:Saveable
Save this model to the given path.This saves: - human-readable (JSON) model metadata to path/metadata/ - Parquet formatted data to path/data/
The model may be loaded using
Loader.load
.
-