spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutl...@apache.org
Subject spark git commit: [SPARK-23162][PYSPARK][ML] Add r2adj into Python API in LinearRegressionSummary
Date Mon, 26 Mar 2018 22:45:57 GMT
Repository: spark
Updated Branches:
  refs/heads/master b30a7d28b -> 3e778f5a9


[SPARK-23162][PYSPARK][ML] Add r2adj into Python API in LinearRegressionSummary

## What changes were proposed in this pull request?

Adding r2adj in LinearRegressionSummary for Python API.

## How was this patch tested?

Added unit tests to exercise the api calls for the summary classes in tests.py.

Author: Kevin Yu <qyu@us.ibm.com>

Closes #20842 from kevinyu98/spark-23162.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/3e778f5a
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/3e778f5a
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/3e778f5a

Branch: refs/heads/master
Commit: 3e778f5a91b0553b09fe0e0ee84d771a71504960
Parents: b30a7d2
Author: Kevin Yu <qyu@us.ibm.com>
Authored: Mon Mar 26 15:45:27 2018 -0700
Committer: Bryan Cutler <cutlerb@gmail.com>
Committed: Mon Mar 26 15:45:27 2018 -0700

----------------------------------------------------------------------
 python/pyspark/ml/regression.py | 18 ++++++++++++++++--
 python/pyspark/ml/tests.py      |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/3e778f5a/python/pyspark/ml/regression.py
----------------------------------------------------------------------
diff --git a/python/pyspark/ml/regression.py b/python/pyspark/ml/regression.py
index de0a0fa..9a66d87 100644
--- a/python/pyspark/ml/regression.py
+++ b/python/pyspark/ml/regression.py
@@ -336,10 +336,10 @@ class LinearRegressionSummary(JavaWrapper):
     @since("2.0.0")
     def r2(self):
         """
-        Returns R^2^, the coefficient of determination.
+        Returns R^2, the coefficient of determination.
 
         .. seealso:: `Wikipedia coefficient of determination \
-        <http://en.wikipedia.org/wiki/Coefficient_of_determination>`
+        <http://en.wikipedia.org/wiki/Coefficient_of_determination>`_
 
         .. note:: This ignores instance weights (setting all to 1.0) from
             `LinearRegression.weightCol`. This will change in later Spark
@@ -348,6 +348,20 @@ class LinearRegressionSummary(JavaWrapper):
         return self._call_java("r2")
 
     @property
+    @since("2.4.0")
+    def r2adj(self):
+        """
+        Returns Adjusted R^2, the adjusted coefficient of determination.
+
+        .. seealso:: `Wikipedia coefficient of determination, Adjusted R^2 \
+        <https://en.wikipedia.org/wiki/Coefficient_of_determination#Adjusted_R2>`_
+
+        .. note:: This ignores instance weights (setting all to 1.0) from
+            `LinearRegression.weightCol`. This will change in later Spark versions.
+        """
+        return self._call_java("r2adj")
+
+    @property
     @since("2.0.0")
     def residuals(self):
         """

http://git-wip-us.apache.org/repos/asf/spark/blob/3e778f5a/python/pyspark/ml/tests.py
----------------------------------------------------------------------
diff --git a/python/pyspark/ml/tests.py b/python/pyspark/ml/tests.py
index cf1ffa1..6b4376c 100755
--- a/python/pyspark/ml/tests.py
+++ b/python/pyspark/ml/tests.py
@@ -1559,6 +1559,7 @@ class TrainingSummaryTest(SparkSessionTestCase):
         self.assertAlmostEqual(s.meanSquaredError, 0.0)
         self.assertAlmostEqual(s.rootMeanSquaredError, 0.0)
         self.assertAlmostEqual(s.r2, 1.0, 2)
+        self.assertAlmostEqual(s.r2adj, 1.0, 2)
         self.assertTrue(isinstance(s.residuals, DataFrame))
         self.assertEqual(s.numInstances, 2)
         self.assertEqual(s.degreesOfFreedom, 1)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org


Mime
View raw message