library(rpart.plot)
## Loading required package: rpart
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)
prp(ct1, type=0, extra = 101)
## 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)
## 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.
set.seed(1234)
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
## 7       1          0         0
## 11      1          0         0
## 12      1          0         0
## 15      1          0         0
## 16      1          0         0
ps2 <- predict(ct, ts, type="class")
head(ps2)
##      1      7     11     12     15     16 
## 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         15         1
##   virginica       0          3        13
100*(1-sum(diag(cm))/sum(cm))
## [1] 8