Skip to contents

This function sets custom code to be run when the Forest is making a decision from its many trees. This function should be run before you run predict or YARF_update_with_oob_results so that your custom aggregation can be employed. This function is optional as the default aggregation method corresponds to (a) the sample average for regression and (b) the modal category for classification. One further note of warning: once this script has been set, it will be retained in the YARF model until this function is run again for this YARF model object with a new aggregation script. Set aggregation_script = NULL if you wish to reset.

Usage

YARF_set_aggregation_method(yarf_mod, aggregation_script)

Arguments

yarf_mod

The yarf model object

aggregation_script

A custom javascript function which aggregates the predictions in the trees for one observations into one scalar prediction (see below).

function aggregateYhatsIntoOneYhat(y_hats, yarf){ //y_hats is an array of doubles of size num_trees //and yarf provides access to the entire random forest object if needed (of type YARF.YARF)

...

return double //this is the final predicted value aggregated from all tree predictions

}

Value

The yarf model object (invisibly)

Author

Adam Kapelner