Learn R Programming

PPtreeExt (version 0.1.0)

predict.PPtreeExtclass: Predict Method for Projection Pursuit Classification Tree Extensions

Description

Predicts class labels for new observations using a fitted projection pursuit classification tree and optionally calculates prediction error when true class labels are provided.

Usage

# S3 method for PPtreeExtclass
predict(object, newdata, true.class = NULL, ...)

Value

A list with two components:

predict.class

A character vector of predicted class labels for each observation in newdata.

predict.error

Integer count of prediction errors (misclassifications). Only computed when true.class is provided; otherwise returns NA.

Arguments

object

An object of class "PPtreeExtclass" from PPtreeExtclass or PPtreeExt_split.

newdata

A data frame or matrix containing the predictor variables for which predictions are to be made. Must contain the same variables (in the same order) as used in the training data, but without the class variable.

true.class

Optional vector of true class labels for the test data. If provided, prediction error will be calculated. Can be either numeric or factor. Default is NULL.

...

Additional arguments (currently not used).

Examples

Run this code
data(penguins)
penguins <- na.omit(penguins[, -c(2,7, 8)])
require(rsample)
penguins_spl <- rsample::initial_split(penguins, strata=species)
penguins_train <- training(penguins_spl)
penguins_test <- testing(penguins_spl)
penguins_ppt <- PPtreeExtclass(species~bill_len + bill_dep +
flipper_len + body_mass, data = penguins_train, PPmethod = "LDA", tot =nrow
(penguins_train), tol=0.5)
predict(object = penguins_ppt, newdata = penguins_test[,-1], true.class = penguins_test$species)

Run the code above in your browser using DataLab