public class KMeans
extends Object
implements scala.Serializable, org.apache.spark.internal.Logging
This is an iterative algorithm that will make multiple passes over the data, so any RDDs given to it should be cached by the user.
Constructor and Description |
---|
KMeans()
Constructs a KMeans instance with default parameters: {k: 2, maxIterations: 20,
initializationMode: "k-means||", initializationSteps: 2, epsilon: 1e-4, seed: random,
distanceMeasure: "euclidean"}.
|
Modifier and Type | Method and Description |
---|---|
String |
getDistanceMeasure()
The distance suite used by the algorithm.
|
double |
getEpsilon()
The distance threshold within which we've consider centers to have converged.
|
String |
getInitializationMode()
The initialization algorithm.
|
int |
getInitializationSteps()
Number of steps for the k-means|| initialization mode
|
int |
getK()
Number of clusters to create (k).
|
int |
getMaxIterations()
Maximum number of iterations allowed.
|
long |
getSeed()
The random seed for cluster initialization.
|
static String |
K_MEANS_PARALLEL() |
static String |
RANDOM() |
KMeansModel |
run(RDD<Vector> data)
Train a K-means model on the given set of points;
data should be cached for high
performance, because this is an iterative algorithm. |
KMeans |
setDistanceMeasure(String distanceMeasure)
Set the distance suite used by the algorithm.
|
KMeans |
setEpsilon(double epsilon)
Set the distance threshold within which we've consider centers to have converged.
|
KMeans |
setInitializationMode(String initializationMode)
Set the initialization algorithm.
|
KMeans |
setInitializationSteps(int initializationSteps)
Set the number of steps for the k-means|| initialization mode.
|
KMeans |
setInitialModel(KMeansModel model)
Set the initial starting point, bypassing the random initialization or k-means||
The condition model.k == this.k must be met, failure results
in an IllegalArgumentException.
|
KMeans |
setK(int k)
Set the number of clusters to create (k).
|
KMeans |
setMaxIterations(int maxIterations)
Set maximum number of iterations allowed.
|
KMeans |
setSeed(long seed)
Set the random seed for cluster initialization.
|
static KMeansModel |
train(RDD<Vector> data,
int k,
int maxIterations)
Trains a k-means model using specified parameters and the default values for unspecified.
|
static KMeansModel |
train(RDD<Vector> data,
int k,
int maxIterations,
String initializationMode)
Trains a k-means model using the given set of parameters.
|
static KMeansModel |
train(RDD<Vector> data,
int k,
int maxIterations,
String initializationMode,
long seed)
Trains a k-means model using the given set of parameters.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
$init$, initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, initLock, isTraceEnabled, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning, org$apache$spark$internal$Logging$$log__$eq, org$apache$spark$internal$Logging$$log_, uninitialize
public KMeans()
public static String RANDOM()
public static String K_MEANS_PARALLEL()
public static KMeansModel train(RDD<Vector> data, int k, int maxIterations, String initializationMode, long seed)
data
- Training points as an RDD
of Vector
types.k
- Number of clusters to create.maxIterations
- Maximum number of iterations allowed.initializationMode
- The initialization algorithm. This can either be "random" or
"k-means||". (default: "k-means||")seed
- Random seed for cluster initialization. Default is to generate seed based
on system time.public static KMeansModel train(RDD<Vector> data, int k, int maxIterations, String initializationMode)
data
- Training points as an RDD
of Vector
types.k
- Number of clusters to create.maxIterations
- Maximum number of iterations allowed.initializationMode
- The initialization algorithm. This can either be "random" or
"k-means||". (default: "k-means||")public static KMeansModel train(RDD<Vector> data, int k, int maxIterations)
data
- (undocumented)k
- (undocumented)maxIterations
- (undocumented)public int getK()
public KMeans setK(int k)
k
- (undocumented)public int getMaxIterations()
public KMeans setMaxIterations(int maxIterations)
maxIterations
- (undocumented)public String getInitializationMode()
public KMeans setInitializationMode(String initializationMode)
initializationMode
- (undocumented)public int getInitializationSteps()
public KMeans setInitializationSteps(int initializationSteps)
initializationSteps
- (undocumented)public double getEpsilon()
public KMeans setEpsilon(double epsilon)
epsilon
- (undocumented)public long getSeed()
public KMeans setSeed(long seed)
seed
- (undocumented)public String getDistanceMeasure()
public KMeans setDistanceMeasure(String distanceMeasure)
distanceMeasure
- (undocumented)public KMeans setInitialModel(KMeansModel model)
model
- (undocumented)public KMeansModel run(RDD<Vector> data)
data
should be cached for high
performance, because this is an iterative algorithm.data
- (undocumented)