Skip to contents

Prediction accuracy of ODRF at different tree sizes.

Usage

Accuracy(obj, data, newdata = NULL)

Arguments

obj

An object of class ODRF, as that created by the function ODRF.

data

Training data of class data.frame in ODRF is used to calculate the OOB error.

newdata

A data frame or matrix containing new data is used to calculate the test error. If it is missing, then it is replaced by data.

Value

OOB error and test error, misclassification rate (MR) for classification or mean square error (MSE) for regression.

Examples

data(breast_cancer)
set.seed(221212)
train <- sample(1:569, 80)
train_data <- data.frame(breast_cancer[train, -1])
test_data <- data.frame(breast_cancer[-train, -1])

forest <- ODRF(diagnosis ~ ., train_data, split = "gini",
parallel = FALSE, ntrees = 50)
(error <- Accuracy(forest, train_data, test_data))
#> $err.oob
#>  [1] 0.09677419 0.06382979 0.05555556 0.03389831 0.02941176 0.04166667
#>  [7] 0.05263158 0.08974359 0.07692308 0.06250000 0.06250000 0.05000000
#> [13] 0.02500000 0.05000000 0.07500000 0.06250000 0.05000000 0.06250000
#> [19] 0.06250000 0.06250000 0.06250000 0.06250000 0.06250000 0.06250000
#> [25] 0.06250000 0.06250000 0.06250000 0.05000000 0.05000000 0.03750000
#> [31] 0.05000000 0.05000000 0.05000000 0.05000000 0.03750000 0.05000000
#> [37] 0.05000000 0.05000000 0.03750000 0.05000000 0.03750000 0.03750000
#> [43] 0.03750000 0.03750000 0.03750000 0.03750000 0.03750000 0.03750000
#> [49] 0.03750000 0.03750000
#> 
#> $err.test
#>  [1] 0.12883436 0.09202454 0.05725971 0.04907975 0.06952965 0.06952965
#>  [7] 0.05112474 0.05725971 0.04498978 0.05316973 0.04907975 0.04907975
#> [13] 0.04498978 0.04498978 0.05112474 0.05521472 0.04703476 0.05112474
#> [19] 0.05316973 0.04907975 0.05316973 0.04703476 0.04907975 0.05316973
#> [25] 0.05112474 0.05521472 0.05316973 0.05521472 0.05521472 0.05725971
#> [31] 0.05725971 0.05930470 0.05521472 0.05521472 0.05521472 0.05725971
#> [37] 0.05725971 0.05316973 0.05316973 0.05521472 0.05316973 0.05316973
#> [43] 0.05316973 0.05521472 0.05521472 0.05316973 0.05316973 0.05112474
#> [49] 0.05316973 0.05112474
#> 
#> $split
#> [1] "gini"
#> 
#> attr(,"class")
#> [1] "Accuracy"