From 129f2f455da982ec9fab593299fa4021b62827eb Mon Sep 17 00:00:00 2001 From: sethah Date: Fri, 15 Apr 2016 12:14:41 -0700 Subject: [SPARK-14104][PYSPARK][ML] All Python param setters should use the `_set` method ## What changes were proposed in this pull request? Param setters in python previously accessed the _paramMap directly to update values. The `_set` method now implements type checking, so it should be used to update all parameters. This PR eliminates all direct accesses to `_paramMap` besides the one in the `_set` method to ensure type checking happens. Additional changes: * [SPARK-13068](https://github.com/apache/spark/pull/11663) missed adding type converters in evaluation.py so those are done here * An incorrect `toBoolean` type converter was used for StringIndexer `handleInvalid` param in previous PR. This is fixed here. ## How was this patch tested? Existing unit tests verify that parameters are still set properly. No new functionality is actually added in this PR. Author: sethah Closes #11939 from sethah/SPARK-14104. --- python/pyspark/ml/clustering.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'python/pyspark/ml/clustering.py') diff --git a/python/pyspark/ml/clustering.py b/python/pyspark/ml/clustering.py index f071c597c8..64c4bf1b92 100644 --- a/python/pyspark/ml/clustering.py +++ b/python/pyspark/ml/clustering.py @@ -130,7 +130,7 @@ class KMeans(JavaEstimator, HasFeaturesCol, HasPredictionCol, HasMaxIter, HasTol """ Sets the value of :py:attr:`k`. """ - self._paramMap[self.k] = value + self._set(k=value) return self @since("1.5.0") @@ -145,7 +145,7 @@ class KMeans(JavaEstimator, HasFeaturesCol, HasPredictionCol, HasMaxIter, HasTol """ Sets the value of :py:attr:`initMode`. """ - self._paramMap[self.initMode] = value + self._set(initMode=value) return self @since("1.5.0") @@ -160,7 +160,7 @@ class KMeans(JavaEstimator, HasFeaturesCol, HasPredictionCol, HasMaxIter, HasTol """ Sets the value of :py:attr:`initSteps`. """ - self._paramMap[self.initSteps] = value + self._set(initSteps=value) return self @since("1.5.0") @@ -280,7 +280,7 @@ class BisectingKMeans(JavaEstimator, HasFeaturesCol, HasPredictionCol, HasMaxIte """ Sets the value of :py:attr:`k`. """ - self._paramMap[self.k] = value + self._set(k=value) return self @since("2.0.0") @@ -295,7 +295,7 @@ class BisectingKMeans(JavaEstimator, HasFeaturesCol, HasPredictionCol, HasMaxIte """ Sets the value of :py:attr:`minDivisibleClusterSize`. """ - self._paramMap[self.minDivisibleClusterSize] = value + self._set(minDivisibleClusterSize=value) return self @since("2.0.0") -- cgit v1.2.3