RandomForestRegressor {less}R Documentation

RandomForestRegressor

Description

Wrapper R6 Class of randomForest::randomForest function that can be used for LESSRegressor and LESSClassifier

Value

R6 Class of RandomForestRegressor

Super classes

less::BaseEstimator -> less::SklearnEstimator -> RandomForestRegressor

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of R6 Class of RandomForestRegressor

Usage
RandomForestRegressor$new(
  n_estimators = 100,
  random_state = NULL,
  min_samples_leaf = 1,
  max_leaf_nodes = NULL
)
Arguments
n_estimators

Number of trees to grow. This should not be set to too small a number, to ensure that every input row gets predicted at least a few times (defaults to 100).

random_state

Seed number to be used for fixing the randomness (default to NULL).

min_samples_leaf

Minimum size of terminal nodes. Setting this number larger causes smaller trees to be grown (and thus take less time) (defaults to 1)

max_leaf_nodes

Maximum number of terminal nodes trees in the forest can have. If not given, trees are grown to the maximum possible (subject to limits by nodesize). If set larger than maximum possible, a warning is issued. (defaults to NULL)

Examples
rf <- RandomForestRegressor$new()
rf <- RandomForestRegressor$new(n_estimators = 500)
rf <- RandomForestRegressor$new(n_estimators = 500, random_state = 100)

Method fit()

Builds a random forest regressor from the training set (X, y).

Usage
RandomForestRegressor$fit(X, y)
Arguments
X

2D matrix or dataframe that includes predictors

y

1D vector or (n,1) dimensional matrix/dataframe that includes response variables

Returns

Fitted R6 Class of RandomForestRegressor

Examples
data(abalone)
split_list <- train_test_split(abalone[1:100,], test_size =  0.3)
X_train <- split_list[[1]]
X_test <- split_list[[2]]
y_train <- split_list[[3]]
y_test <- split_list[[4]]

rf <- RandomForestRegressor$new()
rf$fit(X_train, y_train)

Method predict()

Predict regression value for X0.

Usage
RandomForestRegressor$predict(X0)
Arguments
X0

2D matrix or dataframe that includes predictors

Returns

The predict values.

Examples
preds <- rf$predict(X_test)
print(head(matrix(c(y_test, preds), ncol = 2, dimnames = (list(NULL, c("True", "Prediction"))))))

Method get_estimator_type()

Auxiliary function returning the estimator type e.g 'regressor', 'classifier'

Usage
RandomForestRegressor$get_estimator_type()
Examples
rf$get_estimator_type()

Method clone()

The objects of this class are cloneable with this method.

Usage
RandomForestRegressor$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

randomForest::randomForest()

Examples


## ------------------------------------------------
## Method `RandomForestRegressor$new`
## ------------------------------------------------

rf <- RandomForestRegressor$new()
rf <- RandomForestRegressor$new(n_estimators = 500)
rf <- RandomForestRegressor$new(n_estimators = 500, random_state = 100)

## ------------------------------------------------
## Method `RandomForestRegressor$fit`
## ------------------------------------------------

data(abalone)
split_list <- train_test_split(abalone[1:100,], test_size =  0.3)
X_train <- split_list[[1]]
X_test <- split_list[[2]]
y_train <- split_list[[3]]
y_test <- split_list[[4]]

rf <- RandomForestRegressor$new()
rf$fit(X_train, y_train)

## ------------------------------------------------
## Method `RandomForestRegressor$predict`
## ------------------------------------------------

preds <- rf$predict(X_test)
print(head(matrix(c(y_test, preds), ncol = 2, dimnames = (list(NULL, c("True", "Prediction"))))))

## ------------------------------------------------
## Method `RandomForestRegressor$get_estimator_type`
## ------------------------------------------------

rf$get_estimator_type()

[Package less version 0.1.0 Index]