Skip to contents

Predicts classes for new data using a CBA classifier.

Usage

# S3 method for class 'CBA'
predict(object, newdata, type = c("class", "score"), ...)

accuracy(pred, true)

Arguments

object

An object of class CBA.

newdata

A data.frame or arules::transactions containing rows of new entries to be classified.

type

Predict "class" labels. Some classifiers can also return "scores".

...

Additional arguments are ignored.

pred, true

two factors with the same level representing the predictions and the ground truth (e.g., obtained with response()).

Value

A factor vector with the classification result.

See also

Author

Michael Hahsler

Examples

data("iris")

train_id <- sample(seq_len(nrow(iris)), 130)
iris_train <- iris[train_id, ]
iris_test <- iris[-train_id, ]

cl <- CBA(Species ~., iris_train)
pr <- predict(cl, iris_test)
pr
#>  [1] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [7] versicolor versicolor versicolor versicolor versicolor virginica 
#> [13] virginica  virginica  virginica  virginica  virginica  virginica 
#> [19] virginica  virginica 
#> Levels: setosa versicolor virginica

accuracy(pr, response(Species ~., iris_test))
#> [1] 1