library(rattle)
## Warning: package 'rattle' was built under R version 4.2.1
## Loading required package: tibble
## Loading required package: bitops
## Rattle: A free graphical interface for data science with R.
## Version 5.5.1 Copyright (c) 2006-2021 Togaware Pty Ltd.
## Type 'rattle()' to shake, rattle, and roll your data.
library(rpart)
## Warning: package 'rpart' was built under R version 4.2.1
weatherDS <- new.env()
evalq({
data <- weather
nobs <- nrow(data)
vars <- -grep('^(Date|Locat|RISK)', names(weather))
}, weatherDS)
evalq({
set.seed(42)
train <- sample(nobs, 0.7*nobs)
}, weatherDS)
evalq({
form <- formula(RainTomorrow ~.)
}, weatherDS)
weatherRPART <- new.env(parent=weatherDS)
set.seed(41)
evalq({
control <- rpart.control(cp=0, minbucket=0)
model <- rpart(formula=form,
data=data[train, vars],
control=control)
}, weatherRPART)
print(weatherRPART$model$cptable)
## CP nsplit rel error xerror xstd
## 1 0.119047619 0 1.00000000 1.0000000 0.1410790
## 2 0.095238095 2 0.76190476 1.0714286 0.1450034
## 3 0.047619048 3 0.66666667 0.9761905 0.1397146
## 4 0.035714286 8 0.40476190 1.0238095 0.1424147
## 5 0.031746032 10 0.33333333 1.0238095 0.1424147
## 6 0.023809524 13 0.23809524 1.0476190 0.1437226
## 7 0.011904762 19 0.09523810 1.2380952 0.1532666
## 8 0.007936508 25 0.02380952 1.2857143 0.1554187
## 9 0.000000000 28 0.00000000 1.3571429 0.1584874
plotcp(weatherRPART$model)
grid()
