Github user dbtsai commented on a diff in the pull request: https://github.com/apache/spark/pull/17117#discussion_r105025280 --- Diff: mllib/src/main/scala/org/apache/spark/ml/clustering/KMeans.scala --- @@ -335,17 +369,70 @@ class KMeans @Since("1.5.0") ( model } + /** + * Check validity for interactions between parameters. + */ + private def assertInitialModelValid(): Unit = { + if ($(initMode) == MLlibKMeans.K_MEANS_INITIAL_MODEL) { + if (isSet(initialModel)) { + val initialModelK = $(initialModel).parentModel.k + if (initialModelK != $(k)) { + throw new IllegalArgumentException("The initial model's cluster count = " + + s"$initialModelK, mismatched with k = $k.") + } + } else { + throw new IllegalArgumentException("Users must set param initialModel if you choose " + + "'initialModel' as the initialization algorithm.") + } + } else { + if (isSet(initialModel)) { + logWarning(s"Param initialModel will take no effect when initMode is $initMode.") + } + } + } + @Since("1.5.0") override def transformSchema(schema: StructType): StructType = { + assertInitialModelValid() --- End diff -- `transformSchema ` is called in `transform` method, and `model.transform` is called in computing the summary. I think we should fail it earlier instead of checking it in the end. Also, it's implicit that it's being checked when computing summary. We should explicitly check it. If we have small logic in checking, I'll have those checking code in `fit` method.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org