public class KMeansModel extends Object implements Saveable, scala.Serializable, PMMLExportable
Modifier and Type | Class and Description |
---|---|
static class |
KMeansModel.SaveLoadV1_0$ |
static class |
KMeansModel.SaveLoadV2_0$ |
Constructor and Description |
---|
KMeansModel(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) |
Modifier and Type | Method and Description |
---|---|
Vector[] |
clusterCenters() |
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.
|
String |
distanceMeasure() |
int |
k()
Total number of clusters.
|
static KMeansModel |
load(SparkContext sc,
String path) |
JavaRDD<Integer> |
predict(JavaRDD<Vector> points)
Maps given points to their cluster indices.
|
RDD<Object> |
predict(RDD<Vector> points)
Maps given points to their cluster indices.
|
int |
predict(Vector point)
Returns the cluster index that a given point belongs to.
|
void |
save(SparkContext sc,
String path)
Save this model to the given path.
|
double |
trainingCost() |
public KMeansModel(Vector[] clusterCenters, String distanceMeasure, double trainingCost, int numIter)
public KMeansModel(Vector[] clusterCenters)
public KMeansModel(Iterable<Vector> centers)
centers
- (undocumented)public static KMeansModel load(SparkContext sc, String path)
public Vector[] clusterCenters()
public String distanceMeasure()
public double trainingCost()
public int k()
public int predict(Vector point)
point
- (undocumented)public RDD<Object> predict(RDD<Vector> points)
points
- (undocumented)public JavaRDD<Integer> predict(JavaRDD<Vector> points)
points
- (undocumented)public double computeCost(RDD<Vector> data)
data
- (undocumented)public void save(SparkContext sc, String path)
Saveable
This saves: - human-readable (JSON) model metadata to path/metadata/ - Parquet formatted data to path/data/
The model may be loaded using Loader.load
.