From a291433ed316932618583544ee6d0f1b2f829b80 Mon Sep 17 00:00:00 2001 From: Maxim Gekk Date: Thu, 30 Jan 2020 09:05:14 -0800 Subject: [PATCH] [SPARK-30678][MLLIB][TESTS] Eliminate warnings from deprecated BisectingKMeansModel.computeCost ### What changes were proposed in this pull request? In the PR, I propose to replace deprecated method `computeCost` of `BisectingKMeansModel` by `summary.trainingCost`. ### Why are the changes needed? The changes eliminate deprecation warnings: ``` BisectingKMeansSuite.scala:108: method computeCost in class BisectingKMeansModel is deprecated (since 3.0.0): This method is deprecated and will be removed in future versions. Use ClusteringEvaluator instead. You can also get the cost on the training dataset in the summary. [warn] assert(model.computeCost(dataset) < 0.1) BisectingKMeansSuite.scala:135: method computeCost in class BisectingKMeansModel is deprecated (since 3.0.0): This method is deprecated and will be removed in future versions. Use ClusteringEvaluator instead. You can also get the cost on the training dataset in the summary. [warn] assert(model.computeCost(dataset) == summary.trainingCost) BisectingKMeansSuite.scala:323: method computeCost in class BisectingKMeansModel is deprecated (since 3.0.0): This method is deprecated and will be removed in future versions. Use ClusteringEvaluator instead. You can also get the cost on the training dataset in the summary. [warn] model.computeCost(dataset) ``` ### Does this PR introduce any user-facing change? No ### How was this patch tested? By running `BisectingKMeansSuite` via: ``` ./build/sbt "test:testOnly *BisectingKMeansSuite" ``` Closes #27401 from MaxGekk/kmeans-computeCost-warning. Authored-by: Maxim Gekk Signed-off-by: Dongjoon Hyun --- .../apache/spark/ml/clustering/BisectingKMeansSuite.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mllib/src/test/scala/org/apache/spark/ml/clustering/BisectingKMeansSuite.scala b/mllib/src/test/scala/org/apache/spark/ml/clustering/BisectingKMeansSuite.scala index fc756d4c71..debd0dd65d 100644 --- a/mllib/src/test/scala/org/apache/spark/ml/clustering/BisectingKMeansSuite.scala +++ b/mllib/src/test/scala/org/apache/spark/ml/clustering/BisectingKMeansSuite.scala @@ -105,7 +105,7 @@ class BisectingKMeansSuite extends MLTest with DefaultReadWriteTest { val bkm = new BisectingKMeans().setK(k).setPredictionCol(predictionColName).setSeed(1) val model = bkm.fit(dataset) assert(model.clusterCenters.length === k) - assert(model.computeCost(dataset) < 0.1) + assert(model.summary.trainingCost < 0.1) assert(model.hasParent) testTransformerByGlobalCheckFunc[Tuple1[Vector]](dataset.toDF(), model, @@ -132,7 +132,7 @@ class BisectingKMeansSuite extends MLTest with DefaultReadWriteTest { assert(clusterSizes.forall(_ >= 0)) assert(summary.numIter == 20) assert(summary.trainingCost < 0.1) - assert(model.computeCost(dataset) == summary.trainingCost) + assert(model.summary.trainingCost == summary.trainingCost) model.setSummary(None) assert(!model.hasSummary) @@ -320,7 +320,7 @@ class BisectingKMeansSuite extends MLTest with DefaultReadWriteTest { test("BisectingKMeans with Array input") { def trainAndComputeCost(dataset: DataFrame): Double = { val model = new BisectingKMeans().setK(k).setMaxIter(1).setSeed(1).fit(dataset) - model.computeCost(dataset) + model.summary.trainingCost } val (newDataset, newDatasetD, newDatasetF) = MLTestingUtils.generateArrayFeatureDataset(dataset)