Spark ML Params do not define setters - why?

Viewed 95

I've noticed that most (or all) Spark ML traits extending Params, like HasRegParam or in general Has<whatever>Param, do not define setters, but they do define getters. See:

https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/ml/param/shared/sharedParams.scala

The setters are normally defined by the subclasses of ML models extending them, like LinearRegression and so on. Sometimes this means defining the same setter again across multiple classes because several models have a regularization parameter (for instance).

What is the reason for this, instead of defining the setters (e.g. setRegParam) in each of the Params subclasses (e.g. in trait HasRegParam) ? I suspect it is because of the return type of the setters, this.type that enables chained calls when setting multiple params of a ML model. I did not try myself, but maybe this.type does not work properly with chained calls if defined only once in the Params trait instead of each concrete model class?

Is there a cleaner way to avoid having to redefine the setter when I am implementing my own Params traits?

Thanks

0 Answers
Related