Skip to content

Commit

Permalink
add r2adj into Python API in LinearRegressionSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinyu98 committed Mar 16, 2018
1 parent 918fb9b commit 12d18b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/pyspark/ml/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,20 @@ def r2(self):
"""
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 \
<https://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 versions.
"""
return self._call_java("r2adj")

@property
@since("2.0.0")
def residuals(self):
Expand Down
1 change: 1 addition & 0 deletions python/pyspark/ml/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ def test_linear_regression_summary(self):
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)
Expand Down

0 comments on commit 12d18b5

Please sign in to comment.