library(DMwR2)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
set.seed(1234)
data(iris)
ct1 <- rpartXse(Species ~ ., iris)
ct2 <- rpartXse(Species ~ ., iris, se=0)
library(rpart.plot)
## Warning: package 'rpart.plot' was built under R version 4.5.1
## Loading required package: rpart
par(mfrow=c(1,2))
prp(ct1, type=0, extra=101)  # left tree
## Warning: Cannot retrieve the data used to build the model (so cannot determine roundint and is.binary for the variables).
## To silence this warning:
##     Call prp with roundint=FALSE,
##     or rebuild the rpart model with model=TRUE.
prp(ct2, type=0, extra=101)  # right tree
## Warning: Cannot retrieve the data used to build the model (so cannot determine roundint and is.binary for the variables).
## To silence this warning:
##     Call prp with roundint=FALSE,
##     or rebuild the rpart model with model=TRUE.

rndSample <- sample(1:nrow(iris), 100)
tr <- iris[rndSample, ]
ts <- iris[- rndSample, ]
ct <- rpartXse(Species ~ ., tr, se=0.5)
psi <- predict(ct, ts)
head(psi)
##   setosa versicolor virginica
## 1      1          0         0
## 2      1          0         0
## 5      1          0         0
## 6      1          0         0
## 8      1          0         0
## 9      1          0         0
ps2 <- predict(ct, ts, type="class")
head(ps2)
##      1      2      5      6      8      9 
## setosa setosa setosa setosa setosa setosa 
## Levels: setosa versicolor virginica
(cm <- table(ps2, ts$Species))
##             
## ps2          setosa versicolor virginica
##   setosa         18          0         0
##   versicolor      0         18         3
##   virginica       0          1        10
100*(1-sum(diag(cm))/sum(cm))   # the error rate  
## [1] 8







## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```