simpleRF: simpleRF

View source: R/simpleRF.R

simpleRFR Documentation

simpleRF

Description

Implements Random Forests (Breiman 2001) with emphasis on simplicity. Uses reference classes and only plain R. Not optimized for computation speed. Allows rapid prototyping of RF-type algorithms.

Usage

simpleRF(formula, data, num_trees = 50, mtry = NULL,
  min_node_size = NULL, replace = TRUE, probability = FALSE,
  splitrule = NULL, unordered_factors = "ignore", num_threads = 1)

Arguments

formula

Object of class formula or character describing the model to fit.

data

Training data of class data.frame.

num_trees

Number of trees.

mtry

Number of variables to possibly split at in each node.

min_node_size

Minimal node size. Default 1 for classification, 5 for regression, 3 for survival and 10 for probability estimation.

replace

Sample with replacement. Default TRUE.

probability

Grow a probability forest. Default FALSE.

splitrule

Splitrule to use in trees. Default "Gini" for classification and probability forests, "Variance" for regression forests and "Logrank" for survival forests.

unordered_factors

How to handle unordered factor variables. One of "ignore", "order_once", "order_split" and "partition" with default "ignore".

num_threads

Number of threads used for mclapply, set to 1 for debugging.

Details

Unordered factor variables can be handled in different ways. Use "ignore" to treat them as ordered in the order of the factor levels. With "order_once" and "order_split" they are ordered by their response values. For "order_once" this is done once before the analysis, for "order_split" this is done in each split. With "partition" all 2-partitions of the factor levels are considered for splitting.

Author(s)

Marvin N. Wright

References

Breiman, L. (2001). Random forests. Mach Learn, 45(1), 5-32.

Examples


library(simpleRF)

# Classification
simpleRF(Species ~ ., iris)

# Prediction
train_idx <- sample(nrow(iris), 2/3 * nrow(iris))
iris_train <- iris[train_idx, ]
iris_test <- iris[-train_idx, ]
rf_iris <- simpleRF(Species ~ ., data = iris_train)
pred_iris <- rf_iris$predict(iris_test)
table(iris_test$Species, pred_iris)



mnwright/simpleRF documentation built on March 28, 2022, 8:57 a.m.