| fru | R Documentation |
Fru is an implementation of Leo Breiman's Random Forest (tm) method. It fits an ensemble of decision trees built on bootstrap resamples of observations and additionally permuted by constraining split optimisation to a random subset of features. The ensemble prediction is than established from individual trees by voting. Thanks to its construction, the model can also provide a cross-validation-like internal approximation of error, so called out-of-bag predictions, as well as importance scores for features.
fru(
x,
y,
trees = 500L,
tries,
forest = FALSE,
oob = TRUE,
importance = FALSE,
solidify = FALSE,
threads = 0L
)
x |
Data frame containing predictors; must only contain logical, numeric, integer or factor columns, without NAs. |
y |
Decision; either a factor or logical, for classification, or numeric, for regression. Integer decision will be silently converted into a real vector and treated as such afterwards. NA values are not accepted. |
trees |
Number of trees to grow, a single number larger than zero.
Also called |
tries |
Number of features to try at each split, a single number larger than zero and not larger than the number of columns in |
forest |
If set to |
oob |
If set to |
importance |
If set to |
solidify |
If set to |
threads |
Number of threads to use; by default, or when set to 0, fru will try to use all available computing cores. |
In comparison to similar packages, fru is a tailored towards stability, correctness, efficiency and scalability on modern multithreaded machines, providing solid foundation for large data analysis, higher-level methods or production pipeline. To this end, fru exposes only the original hyper-parameters and provides only the permutational importance, though calculated with a novel algorithm that alleviates its greater computational burden.
Fru accepts logical, numeric (including integer) and factor features; NAs are not allowed and will result in error. Logical features are always split into false/true groups without optimisation, yet are scored via weighted Gini impurity (for classification) or variance reduction (for regression), in order to be compared with splits on other features. For numerical features, threshold value is optimised by an exhaustive scan of the criterion above; real values get threshold as a mid-point between values around the split, while integer values as a minimal of the two. In case of a tie in the score, a smaller threshold is used. Ordered factors or factors with six or more levels are treated as numerical, so follow the above procedure. Unordered factors with five or less levels are split by finding a level partition into two subsets via an exhaustive scan of all possibilities, scored, as above, by Gini impurity or variance drop, depending on the forest type.
The maximal tree depth is hard-coded to 512; a critical sample size that triggers branch termination into leaf is one for classification and four for regression; this means that regression needs at least ten objects to be practical. Leaves may be formed from larger samples in same cases, for instance when no split can be found based on the feature samples; in this case, for classification, random tie breaking is used.
Fru uses its own PRNG, the pcg32 method by Melissa E. O'Neill, for its capacity to produce reasonably decorrelated streams, which are used to provide reproducibility of the output in parallel scenarios, regardless of the number of threads.
Namely, fru guarantees that the same trees will be fit for the same input and random seed, although their order may differ.
Thus, OOB predictions and importance scores will be the same up to numerical errors.
PRNG is used in training and prediction on new data; generator is seeded from the R generator, thus standard R interface of set.seed should be used to control it.
The fitted model, an object of a class fru.
Kursa Miron B., Piwoński Krzysztof P. (2026). fru: Fast random forest implementation, SoftwareX 35, 102918.
Breiman Leo (2001). Random Forests, Machine Learning 45, 5-32.
O'Neil Melissa E. (2014). PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation, HMC-CS-2014-0905.
set.seed(1)
data(iris)
fru(iris[,-5],iris[,5],threads=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.