vcr.rpart.newdata | R Documentation |
Produces output for the purpose of constructing graphical displays such as the classmap
on new data. Requires the output of
vcr.rpart.train
as an argument.
vcr.rpart.newdata(Xnew, ynew = NULL, vcr.rpart.train.out,
LOO = FALSE)
Xnew |
data matrix of the new data, with the same
number of columns |
ynew |
factor with class membership of each new case. Can be |
vcr.rpart.train.out |
output of |
LOO |
leave one out. Only used when testing this function on a subset of the training data. Default is |
A list with components:
yintnew |
number of the given class of each case. Can contain |
ynew |
given class label of each case. Can contain |
levels |
levels of the response, from |
predint |
predicted class number of each case. Always exists. |
pred |
predicted label of each case. |
altint |
number of the alternative class. Among the classes different from the given class, it is the one with the highest posterior probability. Is |
altlab |
alternative label if yintnew was given, else |
PAC |
probability of the alternative class. Is |
fig |
distance of each case |
farness |
farness of each case from its given class. Is |
ofarness |
for each case |
Raymaekers J., Rousseeuw P.J.
Raymaekers J., Rousseeuw P.J.(2021). Silhouettes and quasi residual plots for neural nets and tree-based classifiers. (link to open access pdf)
vcr.rpart.train
, classmap
, silplot
, stackedplot
library(rpart)
data("data_titanic")
traindata <- data_titanic[which(data_titanic$dataType == "train"), -13]
str(traindata); table(traindata$y)
set.seed(123) # rpart is not deterministic
rpart.out <- rpart(y ~ Pclass + Sex + SibSp +
Parch + Fare + Embarked,
data = traindata, method = 'class', model = TRUE)
y_train <- traindata[, 12]
x_train <- traindata[, -12]
mytype <- list(nominal = c("Name", "Sex", "Ticket", "Cabin", "Embarked"), ordratio = c("Pclass"))
# These are 5 nominal columns, and one ordinal.
# The variables not listed are by default interval-scaled.
vcrtrain <- vcr.rpart.train(x_train, y_train, rpart.out, mytype)
testdata <- data_titanic[which(data_titanic$dataType == "test"), -13]
dim(testdata)
x_test <- testdata[, -12]
y_test <- testdata[, 12]
vcrtest <- vcr.rpart.newdata(x_test, y_test, vcrtrain)
confmat.vcr(vcrtest)
silplot(vcrtest, classCols = c(2, 4))
classmap(vcrtest, "casualty", classCols = c(2, 4))
classmap(vcrtest, "survived", classCols = c(2, 4))
# For more examples, we refer to the vignette:
## Not run:
vignette("Rpart_examples")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.