-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-16831] [Python] Fixed bug in CrossValidator.avgMetrics #14456
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
Conversation
@@ -234,7 +234,7 @@ def _fit(self, dataset): | |||
model = est.fit(train, epm[j]) | |||
# TODO: duplicate evaluator to take extra params from input | |||
metric = eva.evaluate(model.transform(validation, epm[j])) | |||
metrics[j] += metric | |||
metrics[j] += metric/nFolds |
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.
This may fail style checks but we'll see
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.
OK looks fine actually. Would it be possible to add a little bit to the test above this to demonstrate that the result is correct now? just testing the value of the first element of metrics for example.
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.
Done (2 commits because I made a typo.)
Jenkins add to whitelist |
Jenkins test this please |
Test build #63122 has finished for PR 14456 at commit
|
Test build #63157 has finished for PR 14456 at commit
|
Test build #63158 has finished for PR 14456 at commit
|
@@ -166,6 +166,8 @@ class CrossValidator(Estimator, ValidatorParams): | |||
>>> evaluator = BinaryClassificationEvaluator() | |||
>>> cv = CrossValidator(estimator=lr, estimatorParamMaps=grid, evaluator=evaluator) | |||
>>> cvModel = cv.fit(dataset) | |||
>>> cvModel.avgMetrics[0] | |||
0.5 |
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.
Nice, I assume this would have printed 1.5 before
Merge to master/2.0/1.6 |
avgMetrics was summed, not averaged, across folds Author: =^_^= <maxmoroz@gmail.com> Closes apache#14456 from pkch/pkch-patch-1. (cherry picked from commit 639df04) Signed-off-by: Sean Owen <sowen@cloudera.com> (cherry picked from commit 92ee6fb)
Sorry. I think this pr breaks 1.6 build.
|
Oh dear. I give up on back-porting things to 1.6. It just breaks too much at this stage! I will revert. |
Thanks! Seems #12464 introduced avgMetrics to CrossValidator model. |
Hi everyone, I know this thread is closed and the bug on how Basically, I have setup a
Everything seems to run smoothly, except for the fact that when I'm printing out the performance (i.e., RMSE) of each model (i.e., 9 models for each fold) and I try to "manually" compute the average from each fold, the resulting 9 average values do not match at all with the values I get when I use the internal
As you can see, all the values of RMSE are below 150,000.
There are 9 elements as expected but none of them looks correct! In fact, all of them are above 150,000 even though none of my 45 models (not only the 5 I listed above) reaches those figures. It looks like the way in which I have also tried to inspect the current implementation of the
Interestingly enough, the same happens even if I run k-fold cross validation on Has anyone else experienced the same issue? Many thanks, any help will be much appreciated! NOTE: I have blindly assumed the problem (if any) is on the |
That's weird, I also don't see how it can happen. How did you print the metrics above, just by adding logging statements to spark? just wondering if it's at all possible they're from something else. I tried this locally with a simple setup like yours (different data) and the avgMetrics reports the average of the model across folds exactly. |
Thanks for your reply Sean! My setting is as follows: I'm running PySpark 2.4.5 remotely over Google Colab.
I call the above function as follows:
where Thanks again for your help! |
Oh, you're printing from the training summary. That's RMSE on the training set. The eval metric is the (average of) RMSE on the held-out folds. The result makes sense. |
Ohhh... I got it, thanks! Thanks a lot! |
I don't see that is recorded anywhere. I verified the avg was right just by hacking the code to print them. |
Gotcha! Thanks again for your help! |
What changes were proposed in this pull request?
avgMetrics was summed, not averaged, across folds