Title: | CBA Classifier |
---|---|
Description: | Provides implementations of a classifier based on the "Classification Based on Associations" (CBA). It can be used for building classification models from association rules. Rules are pruned in the order of precedence given by the sort criteria and a default rule is added. The final classifier labels provided instances. CBA was originally proposed by Liu, B. Hsu, W. and Ma, Y. Integrating Classification and Association Rule Mining. Proceedings KDD-98, New York, 27-31 August. AAAI. pp80-86 (1998, ISBN:1-57735-070-7). |
Authors: | Jaroslav Kuchar [aut, cre], Tomas Kliegr [ctb] |
Maintainer: | Jaroslav Kuchar <[email protected]> |
License: | Apache License (== 2.0) |
Version: | 0.4.3 |
Built: | 2024-11-27 06:43:07 UTC |
Source: | CRAN |
Automatic build of the classification model using the Apriori algorithm from the arules
build(trainData, className = NA, pruning = TRUE, sa = list(), verbose = TRUE, parallel = TRUE)
build(trainData, className = NA, pruning = TRUE, sa = list(), verbose = TRUE, parallel = TRUE)
trainData |
|
className |
column name with the target class - default is the last column |
pruning |
performing pruning while building the model |
sa |
simulated annealing setting. Default values: list(temp=100.0, alpha=0.05, tabuRuleLength=5, timeout=10) |
verbose |
verbose indicator |
parallel |
parallel indicator |
list with parameters and model as data.frame with rules
library("rCBA") data("iris") output <- rCBA::build(iris,sa = list(alpha=0.5), parallel=FALSE) # speeding up the cooling model <- output$model predictions <- rCBA::classification(iris, model) table(predictions) sum(as.character(iris$Species)==as.character(predictions), na.rm=TRUE) / length(predictions)
library("rCBA") data("iris") output <- rCBA::build(iris,sa = list(alpha=0.5), parallel=FALSE) # speeding up the cooling model <- output$model predictions <- rCBA::classification(iris, model) table(predictions) sum(as.character(iris$Species)==as.character(predictions), na.rm=TRUE) / length(predictions)
Automatic build of the classification model using the FP-Growth algorithm
buildFPGrowth(train, className = NULL, verbose = TRUE, parallel = TRUE)
buildFPGrowth(train, className = NULL, verbose = TRUE, parallel = TRUE)
train |
|
className |
column name with the target class - default is the last column |
verbose |
verbose indicator |
parallel |
parallel indicator |
list with parameters and model as data.frame with rules
library("rCBA") data("iris") output <- rCBA::buildFPGrowth(iris[sample(nrow(iris), 10),], "Species", parallel=FALSE, verbose=TRUE) inspect(output$model)
library("rCBA") data("iris") output <- rCBA::buildFPGrowth(iris[sample(nrow(iris), 10),], "Species", parallel=FALSE, verbose=TRUE) inspect(output$model)
A classification function
classification(test, rules, verbose = TRUE)
classification(test, rules, verbose = TRUE)
test |
|
rules |
|
verbose |
verbose indicator |
vector with classifications
library("arules") library("rCBA") data("iris") train <- sapply(iris, as.factor) train <- data.frame(train, check.names=FALSE) txns <- as(train,"transactions") rules = apriori(txns, parameter=list(support=0.03, confidence=0.03, minlen=2), appearance = list(rhs=c("Species=setosa", "Species=versicolor", "Species=virginica"),default="lhs")) predictions <- rCBA::classification(train,rules) table(predictions) sum(as.character(train$Species)==as.character(predictions),na.rm=TRUE)/length(predictions)
library("arules") library("rCBA") data("iris") train <- sapply(iris, as.factor) train <- data.frame(train, check.names=FALSE) txns <- as(train,"transactions") rules = apriori(txns, parameter=list(support=0.03, confidence=0.03, minlen=2), appearance = list(rhs=c("Species=setosa", "Species=versicolor", "Species=virginica"),default="lhs")) predictions <- rCBA::classification(train,rules) table(predictions) sum(as.character(train$Species)==as.character(predictions),na.rm=TRUE)/length(predictions)
FP-Growth algorithm - Jiawei Han, Jian Pei, and Yiwen Yin. Mining frequent patterns without candidate generation. SIGMOD Rec. 29, 2 (2000) <doi:10.1145/335191.335372>
fpgrowth(train, support = 0.01, confidence = 1, maxLength = 5, consequent = NULL, verbose = TRUE, parallel = TRUE)
fpgrowth(train, support = 0.01, confidence = 1, maxLength = 5, consequent = NULL, verbose = TRUE, parallel = TRUE)
train |
|
support |
minimum support |
confidence |
minimum confidence |
maxLength |
maximum length |
consequent |
filter consequent - column name with consequent/target class |
verbose |
verbose indicator |
parallel |
parallel indicator |
library("rCBA") data("iris") train <- sapply(iris,as.factor) train <- data.frame(train, check.names=FALSE) txns <- as(train,"transactions") rules = rCBA::fpgrowth(txns, support=0.03, confidence=0.03, maxLength=2, consequent="Species", parallel=FALSE) predictions <- rCBA::classification(train,rules) table(predictions) sum(as.character(train$Species)==as.character(predictions),na.rm=TRUE)/length(predictions) prunedRules <- rCBA::pruning(train, rules, method="m2cba", parallel=FALSE) predictions <- rCBA::classification(train, prunedRules) table(predictions) sum(as.character(train$Species)==as.character(predictions),na.rm=TRUE)/length(predictions)
library("rCBA") data("iris") train <- sapply(iris,as.factor) train <- data.frame(train, check.names=FALSE) txns <- as(train,"transactions") rules = rCBA::fpgrowth(txns, support=0.03, confidence=0.03, maxLength=2, consequent="Species", parallel=FALSE) predictions <- rCBA::classification(train,rules) table(predictions) sum(as.character(train$Species)==as.character(predictions),na.rm=TRUE)/length(predictions) prunedRules <- rCBA::pruning(train, rules, method="m2cba", parallel=FALSE) predictions <- rCBA::classification(train, prunedRules) table(predictions) sum(as.character(train$Species)==as.character(predictions),na.rm=TRUE)/length(predictions)
data.frame
to rules
from arules
Conversion of data.frame
to rules
from arules
frameToRules(model)
frameToRules(model)
model |
|
arules
rules
representation
library("rCBA") model <- data.frame("rules" = c("{X=1} => {Y=1}","{X=0} => {Y=0}"), "support" = c(0.5,0.5), "confidence" = c(0.5,0.5), "lift" = c(1.0,1.0)) rules <- rCBA::frameToRules(model) inspect(rules)
library("rCBA") model <- data.frame("rules" = c("{X=1} => {Y=1}","{X=0} => {Y=0}"), "support" = c(0.5,0.5), "confidence" = c(0.5,0.5), "lift" = c(1.0,1.0)) rules <- rCBA::frameToRules(model) inspect(rules)
A Pruning function
pruning(train, rules, method = "m2cba", verbose = TRUE, parallel = TRUE)
pruning(train, rules, method = "m2cba", verbose = TRUE, parallel = TRUE)
train |
trainData |
rules |
|
method |
pruning method m2cba(default)|m1cba|dcbrcba |
verbose |
verbose indicator |
parallel |
parallel indicator |
data.frame
with pruned rules
library("arules") library("rCBA") data("iris") train <- sapply(iris,as.factor) train <- data.frame(train, check.names=FALSE) txns <- as(train,"transactions") rules = apriori(txns, parameter=list(support=0.03, confidence=0.03, minlen=2), appearance = list(rhs=c("Species=setosa", "Species=versicolor", "Species=virginica"),default="lhs")) print(length(rules)) prunedRules <- rCBA::pruning(train, rules, method="m2cba", parallel=FALSE) print(length(prunedRules))
library("arules") library("rCBA") data("iris") train <- sapply(iris,as.factor) train <- data.frame(train, check.names=FALSE) txns <- as(train,"transactions") rules = apriori(txns, parameter=list(support=0.03, confidence=0.03, minlen=2), appearance = list(rhs=c("Species=setosa", "Species=versicolor", "Species=virginica"),default="lhs")) print(length(rules)) prunedRules <- rCBA::pruning(train, rules, method="m2cba", parallel=FALSE) print(length(prunedRules))