RandomForestRegressor | R Documentation |
Wrapper R6 Class of randomForest::randomForest function that can be used for LESSRegressor and LESSClassifier
R6 Class of RandomForestRegressor
less::BaseEstimator
-> less::SklearnEstimator
-> RandomForestRegressor
new()
Creates a new instance of R6 Class of RandomForestRegressor
RandomForestRegressor$new( n_estimators = 100, random_state = NULL, min_samples_leaf = 1, max_leaf_nodes = NULL )
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)
rf <- RandomForestRegressor$new() rf <- RandomForestRegressor$new(n_estimators = 500) rf <- RandomForestRegressor$new(n_estimators = 500, random_state = 100)
fit()
Builds a random forest regressor from the training set (X, y).
RandomForestRegressor$fit(X, y)
X
2D matrix or dataframe that includes predictors
y
1D vector or (n,1) dimensional matrix/dataframe that includes response variables
Fitted R6 Class of RandomForestRegressor
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)
predict()
Predict regression value for X0.
RandomForestRegressor$predict(X0)
X0
2D matrix or dataframe that includes predictors
The predict values.
preds <- rf$predict(X_test) print(head(matrix(c(y_test, preds), ncol = 2, dimnames = (list(NULL, c("True", "Prediction"))))))
get_estimator_type()
Auxiliary function returning the estimator type e.g 'regressor', 'classifier'
RandomForestRegressor$get_estimator_type()
rf$get_estimator_type()
clone()
The objects of this class are cloneable with this method.
RandomForestRegressor$clone(deep = FALSE)
deep
Whether to make a deep clone.
randomForest::randomForest()
## ------------------------------------------------ ## 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.