predict: Classification with CBA classifier

Description Usage Arguments Details Value Author(s) Examples

Description

Uses a classifier based on association rules to classify a new set of data entries.

Usage

1
2
## S3 method for class 'CBA'
predict(object, newdata, ...)

Arguments

object

A CBA classifier object with a default class and a sorted list of association rules

newdata

A data.frame containing rows of new entries to be classified

...

Additional arguments not used.

Details

Runs a linear pass through newdata and uses the CBA classifier to assign it a class.

Value

Returns a vector of class labels, one for rows in newdata.

Author(s)

Ian Johnson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
data(iris)
irisDisc <- as.data.frame(lapply(iris[1:4], discretize, categories=9))
irisDisc$Species <- iris$Species
irisDisc <- irisDisc[sample(1:nrow(irisDisc)),]


# train classifier on the first 100 examples
classifier <- CBA(Species ~ ., irisDisc[1:100,], supp = 0.05, conf=0.8)
classifier

# predict the class for the remaining 50 examples
results <- predict(classifier, irisDisc[101:150,])
table(results, irisDisc$Species[101:150])

# use caret to get more statistics
library("caret")
confusionMatrix(results, irisDisc$Species[101:150])

Example output

Loading required package: Matrix
Loading required package: arules

Attaching package: 'arules'

The following objects are masked from 'package:base':

    abbreviate, write

CBA Classifier Object
Class: Species (labels: setosa, versicolor, virginica )
Default Class: Species=versicolor
Number of rules: 13
Classification method: first 
Description: CBA algorithm by Liu, et al. 1998 with support=0.05 and
     confidence=0.8

            
results      setosa versicolor virginica
  setosa         19          0         0
  versicolor      0         15        11
  virginica       0          0         5
Loading required package: lattice
Loading required package: ggplot2
Confusion Matrix and Statistics

            Reference
Prediction   setosa versicolor virginica
  setosa         19          0         0
  versicolor      0         15        11
  virginica       0          0         5

Overall Statistics
                                          
               Accuracy : 0.78            
                 95% CI : (0.6404, 0.8847)
    No Information Rate : 0.38            
    P-Value [Acc > NIR] : 9.516e-09       
                                          
                  Kappa : 0.6705          
 Mcnemar's Test P-Value : NA              

Statistics by Class:

                     Class: setosa Class: versicolor Class: virginica
Sensitivity                   1.00            1.0000           0.3125
Specificity                   1.00            0.6857           1.0000
Pos Pred Value                1.00            0.5769           1.0000
Neg Pred Value                1.00            1.0000           0.7556
Prevalence                    0.38            0.3000           0.3200
Detection Rate                0.38            0.3000           0.1000
Detection Prevalence          0.38            0.5200           0.1000
Balanced Accuracy             1.00            0.8429           0.6562

arulesCBA documentation built on July 27, 2017, 9:01 a.m.