RandomForestAutomaticMtryAndNtree: Create random forest classification model after optimizing...

Description Usage Arguments Details Value See Also Examples

View source: R/classification.R

Description

For this function, mtry is optimized using randomForest::tuneRF() and ntree is optimized using find.best.number.of.trees() function on the out-of-bag error. After optimizing for mtry and ntree, the optimal values are used to create a new random forest model, and this model is outputted.

Usage

1
2
3
4
5
6
RandomForestAutomaticMtryAndNtree(
  inputted.data,
  name.of.predictors.to.use,
  target.column.name,
  seed
)

Arguments

inputted.data

A dataframe.

name.of.predictors.to.use

A vector of strings that specifies the columns with values that we want to use for prediction.

target.column.name

A string that specifies the column with values that we want to predict for. This column should be a factor.

seed

A integer that specifies the seed to use for random number generation.

Details

However, the default values of mtry and ntree from randomForest() are actually preferred in most cases.

Value

A randomForest object is returned

See Also

Other Classification functions: CVPredictionsRandomForest(), CVRandomForestClassificationMatrixForPheatmap(), GenerateExampleDataMachinelearnr(), LOOCVPredictionsRandomForestAutomaticMtryAndNtree(), LOOCVRandomForestClassificationMatrixForPheatmap(), RandomForestClassificationGiniMatrixForPheatmap(), RandomForestClassificationPercentileMatrixForPheatmap(), eval.classification.results(), find.best.number.of.trees()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
id = c("1a", "1b", "1c", "1d", "1e", "1f", "1g", "2a", "2b", "2c", "2d", "2e", "2f", "3a",
       "3b", "3c", "3d", "3e", "3f", "3g", "3h", "3i")

x = c(18, 21, 22, 24, 26, 26, 27, 30, 31, 35, 39, 35, 30, 40, 41, 42, 44, 46, 47, 48, 49, 54)

y = c(10, 11, 22, 15, 12, 13, 14, 33, 39, 37, 44, 40, 45, 27, 29, 20, 28, 21, 30, 31, 23, 24)

a = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

b = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)


actual = as.factor(c("1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2",
       "2", "3", "3", "3",
       "3", "3", "3", "3", "3", "3"))

example.data <- data.frame(id, x, y, a, b, actual)

rf.result <- RandomForestAutomaticMtryAndNtree(example.data, c("x", "y", "a", "b"),
"actual", seed=2)

predicted <- rf.result$predicted
actual <- example.data[,"actual"]

#Result is not perfect because RF model does not over fit to the training data.
eval.classification.results(as.character(actual), as.character(predicted), "Example")

yhhc2/machinelearnr documentation built on Dec. 23, 2021, 7:19 p.m.