viirya commented on a change in pull request #29445:
URL: https://github.com/apache/spark/pull/29445#discussion_r475044767
##########
File path: python/pyspark/ml/tuning.py
##########
@@ -536,7 +536,7 @@ def copy(self, extra=None):
bestModel = self.bestModel.copy(extra)
avgMetrics = self.avgMetrics
subModels = self.subModels
- return CrossValidatorModel(bestModel, avgMetrics, subModels)
+ return self._copyValues(CrossValidatorModel(bestModel, avgMetrics,
subModels), extra=extra)
Review comment:
I think I get your point above. You meant if we just shallow copy the
model itself, reassigning of element in `avgMetrics` will be propagated to the
`avgMetrics` in copied model. Because two models use the same `avgMetrics`
reference.
You want to shallow copy `avgMetrics` itself. So two models have difference
`avgMetrics` references. Because `avgMetrics` is a list of float, it is no
matter shallow copy or deep copy.
> By shallow copy I mean copy.copy() in python, which makes re-assigning
cvModel.avgMetrics[0] not being propagated to cvModelCopied.avgMetrics[0].
No matter deep copy or shallow copy, I think reassigning `avgMetrics[0]`
won't propagate to the `avgMetrics[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.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]