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
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic class -
Constructor Summary
ConstructorsConstructorDescriptionKMeansModel(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[]doublecomputeCost(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.intk()Total number of clusters.static KMeansModelload(SparkContext sc, String path) Maps given points to their cluster indices.intReturns the cluster index that a given point belongs to.Maps given points to their cluster indices.voidsave(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:SaveableSave 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.
-