No, tree
is a callable object. It’s actually tree
that gets mutated.
Sorry, @ilkerarslan, the bikeshedding has begun. It’s hard to avoid with ML libraries because lots of people are interested and have opinions.
For those who are interested, I already opened an issue regarding the syntax for fitting a model:
I tend to agree with @mirkobunse that immutable data structures lead to clearer code. The LearnAPI.jl Discourse thread discussed possible designs extensively. The two main options (as I see it) for a functional, immutable design are:
- Two separate immutable types, one to hold the hyperparameters and one that contains the full fitted object. (The full fitted object would most likely also include the hyperparameters.) So fitting and predicting would look like this:
params = RandomForestRegressorParams(n_trees=100) model = fit(params, X, y) ŷ = predict(model, Xnew) # Or `ŷ = model(Xnew)`, as in NovaML and Flux.
- Have a
FittedModel
wrapper type that wraps the hyperparameters and the fitted parameters. StatsLearnModels.jl uses this approach.