-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-12810][PySpark] PySpark CrossValidatorModel should support avgMetrics #12464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,6 +461,31 @@ def _fit(self, dataset): | |
|
|
||
| class CrossValidatorTests(PySparkTestCase): | ||
|
|
||
| def test_copy(self): | ||
| sqlContext = SQLContext(self.sc) | ||
| dataset = sqlContext.createDataFrame([ | ||
| (10, 10.0), | ||
| (50, 50.0), | ||
| (100, 100.0), | ||
| (500, 500.0)] * 10, | ||
| ["feature", "label"]) | ||
|
|
||
| iee = InducedErrorEstimator() | ||
| evaluator = RegressionEvaluator(metricName="rmse") | ||
|
|
||
| grid = (ParamGridBuilder() | ||
| .addGrid(iee.inducedError, [100.0, 0.0, 10000.0]) | ||
| .build()) | ||
| cv = CrossValidator(estimator=iee, estimatorParamMaps=grid, evaluator=evaluator) | ||
| cvCopied = cv.copy() | ||
| self.assertEqual(cv.getEstimator().uid, cvCopied.getEstimator().uid) | ||
|
|
||
| cvModel = cv.fit(dataset) | ||
| cvModelCopied = cvModel.copy() | ||
| for index in range(len(cvModel.avgMetrics)): | ||
| self.assertTrue(abs(cvModel.avgMetrics[index] - cvModelCopied.avgMetrics[index]) | ||
| < 0.0001) | ||
|
|
||
| def test_fit_minimize_metric(self): | ||
| sqlContext = SQLContext(self.sc) | ||
| dataset = sqlContext.createDataFrame([ | ||
|
|
@@ -534,6 +559,8 @@ def test_save_load(self): | |
| cvModel.save(cvModelPath) | ||
| loadedModel = CrossValidatorModel.load(cvModelPath) | ||
| self.assertEqual(loadedModel.bestModel.uid, cvModel.bestModel.uid) | ||
| for index in range(len(loadedModel.avgMetrics)): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor possible suggestion, there are some other places in the doctests where we use numpys assert_almost_equal, it seems like that might simplify things here a bit if you wanted to.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| self.assertTrue(abs(loadedModel.avgMetrics[index] - cvModel.avgMetrics[index]) < 0.0001) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here; why approximate equality? |
||
|
|
||
|
|
||
| class TrainValidationSplitTests(PySparkTestCase): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try assertEqual and find it did not work? Why do we need approximate equality here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried
assertEqualbefore. This test case causes loss of precision under python2 if we useassertEqual. But under python3, it passes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. OK thanks for checking!