Learn R Programming

traineR (version 2.2.11)

train.randomForest: train.randomForest

Description

Provides a wrapping function for the randomForest.

Usage

train.randomForest(formula, data, ..., subset, na.action = na.fail)

Value

A object randomForest.prmdt with additional information to the model that allows to homogenize the results.

Arguments

formula

a formula describing the model to be fitted (for the print method, an randomForest object).

data

an optional data frame containing the variables in the model. By default the variables are taken from the environment which randomForest is called from.

...

optional parameters to be passed to the low level function randomForest.default.

subset

an index vector indicating which rows should be used. (NOTE: If given, this argument must be named.)

na.action

A function to specify the action to be taken if NAs are found. (NOTE: If given, this argument must be named.)

See Also

The internal function is from package randomForest.

Examples

Run this code

# Classification
data("iris")

n <- seq_len(nrow(iris))
.sample <- sample(n, length(n) * 0.75)
data.train <- iris[.sample,]
data.test <- iris[-.sample,]

modelo.rf <- train.randomForest(Species~., data.train)
modelo.rf
prob <- predict(modelo.rf, data.test, type = "prob")
prob
prediccion <- predict(modelo.rf, data.test, type = "class")
prediccion

# Regression
len <- nrow(swiss)
sampl <- sample(x = 1:len,size = len*0.20,replace = FALSE)
ttesting <- swiss[sampl,]
ttraining <- swiss[-sampl,]
model.rf <- train.randomForest(Infant.Mortality~.,ttraining)
prediction <- predict(model.rf, ttesting)
prediction

Run the code above in your browser using DataLab