FOIL: Use FOIL to learn a rule set for classification

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

View source: R/FOIL.R

Description

Build a classifier rule base using FOIL (First Order Inductive Learner), a greedy algorithm that learns rules to distinguish positive from negative examples.

Usage

1
2
FOIL(formula, data, max_len = 3, min_gain = .7, best_k = 5,
    disc.method = "mdlp")

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.

max_len

maximal length of the LHS of the created rules.

min_gain

minimal gain required to expand a rule.

best_k

use the average expected accuracy (laplace) of the best k rules per class for prediction.

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.

Details

Implements FOIL (Quinlan and Cameron-Jones, 1995) to learn rules and then use them as a classifier following Xiaoxin and Han (2003).

For each class, we find the positive and negative examples and lean the rules using FOIL. Then the rules for all classes are combined and sorted by Laplace accuracy on the training data.

Following Xiaoxin and Han (2003), we classify new examples by

  1. select all the rules whose bodies are satisfied by the example;

  2. from the rules select the best k rules per class (highest expected Laplace accuracy);

  3. average the expected Laplace accuracy per class and choose the class with the highest average.

Value

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

Author(s)

Michael Hahsler

References

Quinlan, J.R., Cameron-Jones, R.M. Induction of logic programs: FOIL and related systems. NGCO 13, 287-312 (1995). doi: https://doi.org/10.1007/BF03037228

Yin, Xiaoxin and Jiawei Han. CPAR: Classification based on Predictive Association Rules, SDM, 2003. doi: 10.1137/1.9781611972733.40

See Also

CBA.object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data("iris")

# learn a classifier using automatic default discretization
classifier <- FOIL(Species ~ ., data = iris)
classifier

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

# make predictions for the first few instances of iris
predict(classifier, head(iris))

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: setosa
Number of rules: 9
Classification method: weighted by laplace - using best 5 rules
Description: FOIL-based classifier (Yin and Han, 2003)

    lhs                           rhs                      support confidence      lift   laplace
[1] {Petal.Length=[-Inf,2.45)} => {Species=setosa}     0.333333333 1.00000000 3.0000000 0.9622642
[2] {Sepal.Length=[6.15, Inf],                                                                   
     Petal.Width=[1.75, Inf]}  => {Species=virginica}  0.246666667 1.00000000 3.0000000 0.9500000
[3] {Petal.Length=[4.75, Inf],                                                                   
     Petal.Width=[1.75, Inf]}  => {Species=virginica}  0.300000000 0.97826087 2.9347826 0.9387755
[4] {Petal.Length=[2.45,4.75),                                                                   
     Petal.Width=[0.8,1.75)}   => {Species=versicolor} 0.293333333 0.97777778 2.9333333 0.9375000
[5] {Petal.Length=[4.75, Inf]} => {Species=virginica}  0.326666667 0.89090909 2.6727273 0.8620690
[6] {Sepal.Length=[5.55,6.15),                                                                   
     Petal.Width=[0.8,1.75)}   => {Species=versicolor} 0.146666667 0.91666667 2.7500000 0.8518519
[7] {Sepal.Length=[6.15, Inf],                                                                   
     Petal.Width=[0.8,1.75)}   => {Species=versicolor} 0.106666667 0.88888889 2.6666667 0.8095238
[8] {Sepal.Length=[5.55,6.15),                                                                   
     Sepal.Width=[2.95,3.35)}  => {Species=versicolor} 0.040000000 0.66666667 2.0000000 0.5833333
[9] {Sepal.Length=[-Inf,5.55),                                                                   
     Sepal.Width=[-Inf,2.95)}  => {Species=virginica}  0.006666667 0.07692308 0.2307692 0.1250000
[1] setosa setosa setosa setosa setosa setosa
Levels: setosa versicolor virginica

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