Skip to content

Commit 3e778f5

Browse files
kevinyu98BryanCutler
authored andcommitted
[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 <[email protected]> Closes apache#20842 from kevinyu98/spark-23162.
1 parent b30a7d2 commit 3e778f5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

python/pyspark/ml/regression.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,31 @@ def rootMeanSquaredError(self):
336336
@since("2.0.0")
337337
def r2(self):
338338
"""
339-
Returns R^2^, the coefficient of determination.
339+
Returns R^2, the coefficient of determination.
340340
341341
.. seealso:: `Wikipedia coefficient of determination \
342-
<http://en.wikipedia.org/wiki/Coefficient_of_determination>`
342+
<http://en.wikipedia.org/wiki/Coefficient_of_determination>`_
343343
344344
.. note:: This ignores instance weights (setting all to 1.0) from
345345
`LinearRegression.weightCol`. This will change in later Spark
346346
versions.
347347
"""
348348
return self._call_java("r2")
349349

350+
@property
351+
@since("2.4.0")
352+
def r2adj(self):
353+
"""
354+
Returns Adjusted R^2, the adjusted coefficient of determination.
355+
356+
.. seealso:: `Wikipedia coefficient of determination, Adjusted R^2 \
357+
<https://en.wikipedia.org/wiki/Coefficient_of_determination#Adjusted_R2>`_
358+
359+
.. note:: This ignores instance weights (setting all to 1.0) from
360+
`LinearRegression.weightCol`. This will change in later Spark versions.
361+
"""
362+
return self._call_java("r2adj")
363+
350364
@property
351365
@since("2.0.0")
352366
def residuals(self):

python/pyspark/ml/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@ def test_linear_regression_summary(self):
15591559
self.assertAlmostEqual(s.meanSquaredError, 0.0)
15601560
self.assertAlmostEqual(s.rootMeanSquaredError, 0.0)
15611561
self.assertAlmostEqual(s.r2, 1.0, 2)
1562+
self.assertAlmostEqual(s.r2adj, 1.0, 2)
15621563
self.assertTrue(isinstance(s.residuals, DataFrame))
15631564
self.assertEqual(s.numInstances, 2)
15641565
self.assertEqual(s.degreesOfFreedom, 1)

0 commit comments

Comments
 (0)