CBA: Classification Based on Association Rules Algorithm (CBA)

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/CBA.R

Description

Build a classifier based on association rules using the ranking, pruning and classification strategy of the CBA algorithm by Liu, et al. (1998).

Usage

1
2
3
4
5
6
CBA(formula, data, pruning = "M1",
    parameter = NULL, control = NULL, balanceSupport = FALSE,
    disc.method = "mdlp", verbose = FALSE, ...)

pruneCBA_M1(formula, rules, transactions, verbose = FALSE)
pruneCBA_M2(formula, rules, transactions, verbose = FALSE)

Arguments

formula

A symbolic description of the model to be fitted. Has to be of form class ~ . or class ~ predictor1 + predictor2.

data

A data.frame or a transaction set containing the training data. Data frames are automatically discretized and converted to transactions.

pruning

Pruning strategy used: "M1" or "M2".

parameter, control

Optional parameter and control lists for apriori.

balanceSupport

balanceSupport parameter passed to mineCARs function.

disc.method

Discretization method used to discretize continuous variables if data is a data.frame (default: "mdlp"). See discretizeDF.supervised for more supervised discretization methods.

...

For convenience, additional parameters are used to create the parameter control list for apriori (e.g., to specify the support and confidence thresholds).

rules, transactions

prune a set of rules using a transaction set.

verbose

Show progress?

Details

Implementation the CBA algorithm with the M1 or M2 pruning strategy introduced by Liu, et al. (1998).

Candidate classification association rules (CARs) are mined with the standard APRIORI algorithm. Rules are ranked by confidence, support and size. Then either the M1 or M2 algorithm are used to perform database coverage pruning and to determin the number of rules to use and the default class.

Value

Returns an object of class CBA.object representing the trained classifier.

Author(s)

Ian Johnson and Michael Hahsler

References

Liu, B. Hsu, W. and Ma, Y (1998). Integrating Classification and Association Rule Mining. KDD'98 Proceedings of the Fourth International Conference on Knowledge Discovery and Data Mining, New York, 27-31 August. AAAI. pp. 80-86. https://dl.acm.org/doi/10.5555/3000292.3000305

See Also

CBA.object, mineCARs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
data("iris")

# 1. Learn a classifier using automatic default discretization
classifier <- CBA(Species ~ ., data = iris, supp = 0.05, conf = 0.9)
classifier

# inspect the rule base
inspect(rules(classifier))

# make predictions
predict(classifier, head(iris))
table(pred = predict(classifier, iris), true = iris$Species)


# 2. Learn classifier from transactions (and use verbose)
iris_trans <- prepareTransactions(Species ~ ., iris, disc.method = "mdlp")
iris_trans
classifier <- CBA(Species ~ ., data = iris_trans, supp = 0.05, conf = 0.9, verbose = TRUE)
classifier

# make predictions. Note: response extracts class information from transactions.
predict(classifier, head(iris_trans))
table(pred = predict(classifier, iris_trans), true = response(Species ~ ., iris_trans))

Example output

Loading required package: Matrix
Loading required package: arules

Attaching package:arulesThe following objects are masked frompackage:base:

    abbreviate, write

CBA Classifier Object
Class: 
Default Class: NA
Number of rules: 8
Classification method: first  
Description: CBA algorithm (Liu et al., 1998)

    lhs                           rhs                    support confidence  coverage     lift count size coveredTransactions totalErrors
[1] {Petal.Length=[-Inf,2.45)} => {Species=setosa}     0.3333333  1.0000000 0.3333333 3.000000    50    2                  50          50
[2] {Sepal.Length=[6.15, Inf],                                                                                                           
     Petal.Width=[1.75, Inf]}  => {Species=virginica}  0.2466667  1.0000000 0.2466667 3.000000    37    3                  37          13
[3] {Sepal.Length=[5.55,6.15),                                                                                                           
     Petal.Length=[2.45,4.75)} => {Species=versicolor} 0.1400000  1.0000000 0.1400000 3.000000    21    3                  21          13
[4] {Sepal.Width=[-Inf,2.95),                                                                                                            
     Petal.Width=[1.75, Inf]}  => {Species=virginica}  0.1133333  1.0000000 0.1133333 3.000000    17    3                   5           8
[5] {Sepal.Length=[6.15, Inf],                                                                                                           
     Petal.Length=[2.45,4.75)} => {Species=versicolor} 0.0800000  1.0000000 0.0800000 3.000000    12    3                  12           8
[6] {Sepal.Width=[2.95,3.35),                                                                                                            
     Petal.Length=[2.45,4.75)} => {Species=versicolor} 0.0800000  1.0000000 0.0800000 3.000000    12    3                   1           8
[7] {Petal.Width=[1.75, Inf]}  => {Species=virginica}  0.3000000  0.9782609 0.3066667 2.934783    45    2                   4           6
[8] {}                         => {Species=versicolor} 0.3333333  0.3333333        NA 1.000000   150    1                  20           6
[1] setosa setosa setosa setosa setosa setosa
Levels: setosa versicolor virginica
            true
pred         setosa versicolor virginica
  setosa         50          0         0
  versicolor      0         49         5
  virginica       0          1        45
transactions in sparse format with
 150 transactions (rows) and
 15 items (columns)

Mining CARs...
Apriori

Parameter specification:
 confidence minval smax arem  aval originalSupport maxtime support minlen
        0.9    0.1    1 none FALSE            TRUE       5    0.05      1
 maxlen target  ext
      5  rules TRUE

Algorithmic control:
 filter tree heap memopt load sort verbose
    0.1 TRUE TRUE  FALSE TRUE    2    TRUE

Absolute minimum support count: 7 

set item appearances ...[15 item(s)] done [0.00s].
set transactions ...[15 item(s), 150 transaction(s)] done [0.00s].
sorting and recoding items ... [15 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 3 4 5 done [0.00s].
writing ... [55 rule(s)] done [0.00s].
creating S4 object  ... done [0.00s].

Pruning CARs...
CARs left: 8 
CBA Classifier Object
Class: 
Default Class: NA
Number of rules: 8
Classification method: first  
Description: CBA algorithm (Liu et al., 1998)

[1] setosa setosa setosa setosa setosa setosa
Levels: setosa versicolor virginica
            true
pred         setosa versicolor virginica
  setosa         50          0         0
  versicolor      0         49         5
  virginica       0          1        45

arulesCBA documentation built on April 20, 2020, 5:06 p.m.