JuliaAI / DecisionTree.jl

Julia implementation of Decision Tree (CART) and Random Forest algorithms
Other
342 stars 101 forks source link

Add method `build_forest(model, ...)` to add trees to existing `model` #216

Closed ablaom closed 1 year ago

ablaom commented 1 year ago

Closes #213.

You can now do this:

features, labels = load_data("iris")
model1 = build_forest(labels, features, 2, 150) # n_trees = 150
model = build_forest(model1, labels, features, 2, 50) # add 50 trees

New docstring below.

build_forest(model, labels, features, options...; keyword_options...) Return an updated version of `model` with additional `n_trees=options[2]` added to the forest. Here `options` and `keyword_options` are as for the regular `build_forest` method, which excludes the `model` argument. Even if training data is the same in all `build_forest` calls, it is not practically possible to guarantee adding trees in steps is identical to adding them all at once, because of the way random number generators are generated and used. But in all other respects these approaches are equivalent. # Example ``` features, labels = load_data("iris") features = float.(features) labels = string.(labels) ``` The call ``` model = build_forest(labels, features, 2, 200) # n_trees = 200 ``` is approximately equivalent to ``` model1 = build_forest(labels, features, 2, 150) # n_trees = 150 model = build_forest(model1, labels, features, 2, 50) # n_trees = 50 ```
codecov-commenter commented 1 year ago

Codecov Report

Merging #216 (a05e4cd) into dev (c5df161) will increase coverage by 0.16%. The diff coverage is 96.15%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##              dev     #216      +/-   ##
==========================================
+ Coverage   87.99%   88.15%   +0.16%     
==========================================
  Files          10       10              
  Lines        1249     1266      +17     
==========================================
+ Hits         1099     1116      +17     
  Misses        150      150              
Impacted Files Coverage Δ
src/classification/main.jl 96.16% <90.90%> (+0.05%) :arrow_up:
src/DecisionTree.jl 60.00% <100.00%> (+7.76%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

ablaom commented 1 year ago

@rikhuijzer Could you please take a second look?

ablaom commented 1 year ago

I was away from keyboard in the weekend.

Sounds healthy to me. I am often away from keyboard on weekend. It's just that my weekend finishes earlier than yours 🌐 🥝 😄

Thanks for the prompt review, @rikhuijzer