cv.tree

0th

Percentile

Cross-validation for Choosing Tree Complexity

Runs a K-fold cross-validation experiment to find the deviance or number of misclassifications as a function of the cost-complexity parameter k.

Keywords
tree
Usage
cv.tree(object, rand, FUN = prune.tree, K = 10, ...)
Arguments
object

An object of class "tree".

rand

Optionally an integer vector of the length the number of cases used to create object, assigning the cases to different groups for cross-validation.

FUN

The function to do the pruning.

K

The number of folds of the cross-validation.

Additional arguments to FUN.

Value

A copy of FUN applied to object, with component dev replaced by the cross-validated results from the sum of the dev components of each fit.

See Also

tree, prune.tree

Aliases
  • cv.tree
Examples
# NOT RUN {
data(cpus, package="MASS")
cpus.ltr <- tree(log10(perf) ~ syct + mmin + mmax + cach
     + chmin + chmax, data=cpus)
cv.tree(cpus.ltr, , prune.tree)
# }
Documentation reproduced from package tree, version 1.0-40, License: GPL-2 | GPL-3

Community examples

jshusko at Apr 14, 2020 tree v1.0-40

```r library(ISLR) library(dplyr) library(tree) library(tibble) carseats <- as_tibble(Carseats) %>% mutate(High=as.factor(Sales>8)) train <- sample(1:nrow(carseats), 200) tree.carseats <- tree(High~.-Sales, carseats, subset=train) cv.carseats <- cv.tree(tree.carseats,FUN=prune.misclass) cv.carseats ```