Giter Club home page Giter Club logo

rcba's Introduction

rCBA

Build Status

CBA classifier for R - 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 (1998). Integrating Classification and Association Rule Mining. Proceedings KDD-98, New York, 27-31 August. AAAI. pp80-86.

If you publish your research that uses rCBA, please cite:

@inproceedings{Kuchar:2015:EasyMiner,
  author    = {Stanislav Vojir and Vaclav Zeman and Jaroslav Kuchar and Tomas Kliegr},
  title     = {EasyMiner/R Preview: Towards a Web Interface for Association Rule Learning and Classification in R},
  booktitle = {Proceedings of the RuleML 2015 Challenge, the Special Track on Rule-based Recommender Systems for the Web of Data, the Special Industry Track and the RuleML 2015 Doctoral Consortium hosted by the 9th International Web Rule Symposium (RuleML 2015), Berlin, Germany, August 2-5, 2015.},
  year      = {2015}
}

Installation

The package is available in CRAN repository:

install.packages('rCBA',dependencies=TRUE, repos="http://cran.us.r-project.org")

Development Version Installation

Local installation

Prerequisites:

  • Java 8
  • R packages - devtools, rJava, R.utils

R dependencies installation:

install.packages(c("devtools","rJava"),dependencies=TRUE, repos="http://cran.us.r-project.org")

Reconfiguration of Java in R:

sudo R CMD javareconf

Recompile and reinstall rJava:

install.packages('rJava', type='source', dependencies=TRUE, repos="http://cran.us.r-project.org")

rCBA installation:

library("devtools")
devtools::install_github("jaroslav-kuchar/rCBA")

RStudio Server development environment

Vagrant virtual server:

vagrant up

Rstudio server:

Usage

Example 1 - automatically build model (including pruning) + classification:

library("rCBA")
data("iris")

output <- rCBA::build(iris)
model <- output$model
predictions <- rCBA::classification(iris, model)
table(predictions)
sum(iris$Species==predictions, na.rm=TRUE) / length(predictions)

Example 2 - apriori + pruning:

library("arules")
library("rCBA")

train <- read.csv("./train.csv",header=TRUE) # read data

txns <- as(train,"transactions") # convert
rules <- apriori(txns, parameter = list(confidence = 0.1, support= 0.1, minlen=1, maxlen=5)) # rule mining
rules <- subset( rules, subset = rhs %pin% "y=") # filter
rulesFrame <- as(rules,"data.frame") # convert

print(nrow(rulesFrame))
prunedRulesFrame <- rCBA::pruning(train, rulesFrame, method="m2cba") # m2cba(default)|m1cba|dcbrcba
print(nrow(prunedRulesFrame))

Example 3 - apriori + classification:

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"))
rulesFrame <- as(rules,"data.frame")

predictions <- rCBA::classification(train,rulesFrame)
table(predictions)
sum(train$Species==predictions,na.rm=TRUE)/length(predictions)

prunedRulesFrame <- rCBA::pruning(train, rulesFrame, method="m2cba")
predictions <- rCBA::classification(train, prunedRulesFrame)
table(predictions)
sum(train$Species==predictions,na.rm=TRUE)/length(predictions)

Example 4 - fp-growth + classification:

library("rCBA")
data("iris")

train <- sapply(iris,as.factor)
train <- data.frame(train, check.names=FALSE)
txns <- as(train,"transactions")

rules = fpgrowth(txns, support=0.03, confidence=0.03, maxlen=2, consequent="Species")
rulesFrame <- as(rules,"data.frame")

predictions <- rCBA::classification(train,rulesFrame)
table(predictions)
sum(train$Species==predictions,na.rm=TRUE)/length(predictions)

prunedRulesFrame <- rCBA::pruning(train, rulesFrame, method="m2cba")
predictions <- rCBA::classification(train, prunedRulesFrame)
table(predictions)
sum(train$Species==predictions,na.rm=TRUE)/length(predictions)

Example 5 - fp-growth automatic build:

library("rCBA")
data("iris")

output <- rCBA::buildFPGrowth(iris, "Species")
model <- output$model

predictions <- rCBA::classification(iris, model)
table(predictions)
sum(iris$Species==predictions, na.rm=TRUE) / length(predictions)

Contributors

Licence

Apache License Version 2.0

rcba's People

Contributors

jaroslav-kuchar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rcba's Issues

invalid class “itemMatrix” object: item labels not unique

It looks like that the frameToRules function sometimes returns error "invalid class “itemMatrix” object: item labels not unique"
Some debugging showed that

unique(unlist(sapply(rowItems, function(x) x$ant)))

does not filter out repeating items.
A fix seems to be replacing this with

unique(c(unlist(sapply(rowItems, function(x) x$ant))))

That is

antItems <- unique(c(unlist(sapply(rowItems, function(x) x$ant))))
consItems <- unique(c(unlist(sapply(rowItems, function(x) x$cons))))

Cross Validation

In the examples, I notice that the iris dataset is not split into train and test.

Is cross validation performed by default? Can you please shed some light on this?

fpgrowth error in R

I am trying to fit a fpgrowth model on a in-built data set called Adult. While fitting a model, I was getting an error as shown below.

Error in .jcall(jPruning, "[[Ljava/lang/String;", "fpgrowth", support,  : 
method fpgrowth with signature (DDI)[[Ljava/lang/String; not found

I used the below R code to fit fpgrowth model.

library(rCBA)
data("Adult")
Adult<-as(Adult,"transactions")
rules = rCBA::fpgrowth(Adult, support=0.001, confidence=0.5, maxLength=2)

What's wrong with the above code?

fpgrowth sample code won't work

When I was trying to use the sample code of fpgrowth function, it does not work. The error message is:
Error in fpgrowth(train = txns, support = 0.03, confidence = 0.03, minlen = 2, :
unused argument (minlen = 2)

Numeric columns do not have a numeric type

The final data frame is not type consistent. Numeric columns, confidence, support and lift, have the char type. It is problem if I want to sort data after pruning (I have to transform columns to numeric explicitly).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.