-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-32092][ML][PySpark] Fix parameters not being copied in CrossValidatorModel.copy(), read() and write() #29445
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c745198
Added tests for SPARK-32092
202ffcf
Fixed copy()
fe5837d
Fixed to_java and from_java
c3a8407
Added comments for JIRA reference
850d307
Style changes
b662ee0
Merge remote-tracking branch 'upstream/master'
a7a9163
Updated tests
b831161
Deeper copy and fixed tvs
e7d79be
Linting
ba994fd
Used param pairs for type conversion
fcfac36
Made save load tests more robust to new params
1c98218
Merge remote-tracking branch 'upstream/master'
8ae74d0
Fix typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we use
Params.copylikeCrossValidator?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.
We can. However I just found one potential issue with using
Params.copy(not specific toCrossValidator). It creates a shallow copy ofself(i.e. the models). Hence if we run the below snippetBased on the Scala equivalent I think
avgMetricsshould be shallow copied andsubModelsshould be copied with the copying actions delegated tocopy()of each model. I will push a change to this function.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.
You meant avgMetrics should be or should not be shallow copied?
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.
avgMetricsshould be shallow copied, as tested in https://github.com/Louiszr/spark/blob/8ae74d000ac48d6e293feb4bc3dac31088bf6c6c/python/pyspark/ml/tests/test_tuning.py#L124-L129I think
Params.copywill shallow copy theCrossValidatorModelobject and thus only copy the reference toavgMetricsThere 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.
Hm? I think the test makes sure it isn't shallow copy but deep copy, isn't?
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.
By shallow copy I mean
copy.copy()in python, which makes re-assigningcvModel.avgMetrics[0]not being propagated tocvModelCopied.avgMetrics[0].I am also using
copy.deepcopy()as the reference for deep copy. IfcvModel.avgMetrics[0]is an class instance, then shallow copy will point to the same instance, while deep copy will create a copy of the instance.I think here it doesn't make a difference because
avgMetricsis a list offloat, but in the future if it does become a list of objects then a shallow copy implementation will be sufficient to pass the test.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 think I get your point above. You meant if we just shallow copy the model itself, reassigning of element in
avgMetricswill be propagated to theavgMetricsin copied model. Because two models use the sameavgMetricsreference.You want to shallow copy
avgMetricsitself. So two models have differenceavgMetricsreferences. BecauseavgMetricsis a list of float, it is no matter shallow copy or deep copy.No matter deep copy or shallow copy, I think reassigning
avgMetrics[0]won't propagate to theavgMetrics[0]of copied model. Shallow copy copies object references, reassigning changes references, so won't propagate. Deep copy copies object instance, reassigning changes references too, of course won't propagate either.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.
Agreed with the above.