Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
documentation and numRuns warning change
  • Loading branch information
FlytxtRnD committed Jul 8, 2015
commit c446c58da68b259f34485bb656c303bdaf6a458d
1 change: 1 addition & 0 deletions docs/mllib-clustering.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ 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.
* *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.

**Examples**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,15 @@ class KMeans private (
val initStartTime = System.nanoTime()

// Only one run is allowed when initialModel is given
val numRuns = if (initialModel.nonEmpty) 1 else runs
logWarning("Ignoring runs; one run is allowed when initialModel is given.")
val numRuns = if (initialModel.nonEmpty){
if (runs >1 ) logWarning("Ignoring runs; one run is allowed when initialModel is given.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be careful about Scala style. Look at [https://cwiki.apache.org/confluence/display/SPARK/Spark+Code+Style+Guide] or other parts of the codebase for examples. We try hard to keep a consistent style. Here:

val numRuns = if (initialModel.nonEmpty) {
  if (runs > 1) logWarning("Ignoring runs; one run is allowed when initialModel is given.")
  1
} else {
  runs
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkbradley the if statement is given 2 space indentation..tat's correct rgt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace your current code with the snippet I wrote above (defining numRuns). The current code does not follow the style guide.

1
} else runs


val centers = initialModel match {
case Some(kMeansCenters) => {
Array(kMeansCenters.clusterCenters.map(s => new VectorWithNorm(s, Vectors.norm(s, 2.0))))
Array(kMeansCenters.clusterCenters.map(s => new VectorWithNorm(s)))
}
case None => {
if (initializationMode == KMeans.RANDOM) {
Expand Down