vcr.rpart.train | R Documentation |
Produces output for the purpose of constructing graphical displays such as the classmap
. The user first needs to train a
classification tree on the data by rpart::rpart
.
This then serves as an argument to vcr.rpart.train
.
vcr.rpart.train(X, y, trainfit, type = list(),
k = 5, stand = TRUE)
X |
A rectangular matrix or data frame, where the
columns (variables) may be of mixed type and
may contain |
y |
factor with the given class labels.
It is crucial that |
k |
the number of nearest neighbors used in the farness computation. |
trainfit |
the output of an |
type |
list for specifying some (or all) of the types of the
variables (columns) in |
stand |
whether or not to standardize numerical (interval scaled) variables by their range as in the original |
A list with components:
X |
The input data |
yint |
number of the given class of each case. Can contain |
y |
given class label of each case. Can contain |
levels |
levels of |
predint |
predicted class number of each case. For each case this is the class with the highest posterior probability. 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 |
label of the alternative class. Is |
PAC |
probability of the alternative class. Is |
figparams |
parameters for computing |
fig |
distance of each case |
farness |
farness of each case from its given class. Is |
ofarness |
for each case |
trainfit |
the trainfit used to build the VCR object. |
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.newdata
, 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)
confmat.vcr(vcrtrain)
silplot(vcrtrain, classCols = c(2, 4))
classmap(vcrtrain, "casualty", classCols = c(2, 4))
classmap(vcrtrain, "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.