API Reference

Documentation for the OptimalTrees public interface.

Index

Learners

Tree Refitting

IAI.refit_leaves!Function
refit_leaves!(lnr::OptimalTreeLearner, X::FeatureInput, y::TargetInput...;
              keyword_arguments...)

Refit the models in the leaves of the trained tree of lnr using the supplied data X and y.

See the guide to classification trees with logistic regression for an example of using this function to refit a classification tree with logistic regression in each leaf.

Keyword Arguments

  • sample_weight::SampleWeightInput=nothing: the weighting to give to each data point
  • criterion=:default: the scoring criterion to use when updating the leaf models
  • refit_learner::Union{Nothing,Learner,GridSearch}=nothing: an optional learner or grid search that is used to fit the new model in each leaf
  • prune::Bool=false: whether to prune leaves of the tree that do not contain any of the supplied data. If set to false and there are leaves that do not contain any of the supplied data, an error will be thrown.
IAI.copy_splits_and_refit_leaves!Function
copy_splits_and_refit_leaves!(new_lnr::OptimalTreeLearner,
                              orig_lnr::OptimalTreeLearner,
                              X::FeatureInput, y::TargetInput...;
                              keyword_arguments...)

Copy the tree split structure from orig_lnr into new_lnr and refit the models in each leaf of the tree using data X and y.

See the guide to classification trees with logistic regression for an example of using this function to convert a regression tree into a classification tree with logistic regression models in each leaf.

Supports the same keyword arguments as refit_leaves!.

IAI.prune_trees!Function
prune_trees!(lnr::OptimalTreeLearner, X::FeatureInput, y::TargetInput...;
             keyword_arguments...)

Use the trained trees in lnr along with the supplied validation data X and y to determine the best value for the cp parameter and then prune the trees according to this value.

This can be useful for re-pruning trees to an appropriate level of complexity after using refit_leaves! or copy_splits_and_refit_leaves! to change the models in each leaf.

Keyword Arguments

  • reselect_best_tree::Bool (required): whether to re-select the tree used by the learner. If false, the pruned version of the original tree used by the learner will be used. If true, the pruned tree with the best training performance will be used.
  • sample_weight::SampleWeightInput=nothing: the weighting to give to each data point
  • criterion=:default: the scoring criterion to use when updating the leaf models