Skip to content
Snippets Groups Projects
Unverified Commit 33be4da5 authored by Zheng RuiFeng's avatar Zheng RuiFeng Committed by Sean Owen
Browse files

[SPARK-18427][DOC] Update docs of mllib.KMeans

## What changes were proposed in this pull request?
1,Remove `runs` from docs of mllib.KMeans
2,Add notes for `k` according to comments in sources
## How was this patch tested?
existing tests

Author: Zheng RuiFeng <ruifengz@foxmail.com>

Closes #15873 from zhengruifeng/update_doc_mllib_kmeans.
parent d89bfc92
No related branches found
No related tags found
No related merge requests found
...@@ -24,13 +24,11 @@ variant of the [k-means++](http://en.wikipedia.org/wiki/K-means%2B%2B) method ...@@ -24,13 +24,11 @@ variant of the [k-means++](http://en.wikipedia.org/wiki/K-means%2B%2B) method
called [kmeans||](http://theory.stanford.edu/~sergei/papers/vldb12-kmpar.pdf). called [kmeans||](http://theory.stanford.edu/~sergei/papers/vldb12-kmpar.pdf).
The implementation in `spark.mllib` has the following parameters: The implementation in `spark.mllib` has the following parameters:
* *k* is the number of desired clusters. * *k* is the number of desired clusters. Note that it is possible for fewer than k clusters to be returned, for example, if there are fewer than k distinct points to cluster.
* *maxIterations* is the maximum number of iterations to run. * *maxIterations* is the maximum number of iterations to run.
* *initializationMode* specifies either random initialization or * *initializationMode* specifies either random initialization or
initialization via k-means\|\|. initialization via k-means\|\|.
* *runs* is the number of times to run the k-means algorithm (k-means is not * *runs* This param has no effect since Spark 2.0.0.
guaranteed to find a globally optimal solution, and when run multiple times on
a given dataset, the algorithm returns the best clustering result).
* *initializationSteps* determines the number of steps in the k-means\|\| algorithm. * *initializationSteps* determines the number of steps in the k-means\|\| algorithm.
* *epsilon* determines the distance threshold within which we consider k-means to have converged. * *epsilon* determines the distance threshold within which we consider k-means to have converged.
* *initialModel* is an optional set of cluster centers used for initialization. If this parameter is supplied, only one run is performed. * *initialModel* is an optional set of cluster centers used for initialization. If this parameter is supplied, only one run is performed.
......
...@@ -36,8 +36,7 @@ if __name__ == "__main__": ...@@ -36,8 +36,7 @@ if __name__ == "__main__":
parsedData = data.map(lambda line: array([float(x) for x in line.split(' ')])) parsedData = data.map(lambda line: array([float(x) for x in line.split(' ')]))
# Build the model (cluster the data) # Build the model (cluster the data)
clusters = KMeans.train(parsedData, 2, maxIterations=10, clusters = KMeans.train(parsedData, 2, maxIterations=10, initializationMode="random")
runs=10, initializationMode="random")
# Evaluate clustering by computing Within Set Sum of Squared Errors # Evaluate clustering by computing Within Set Sum of Squared Errors
def error(point): def error(point):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment