Skip to content

Instantly share code, notes, and snippets.

@mwacc
Created July 23, 2013 12:59
Show Gist options
  • Save mwacc/6062181 to your computer and use it in GitHub Desktop.
Save mwacc/6062181 to your computer and use it in GitHub Desktop.
Basket Analytic (Frequent Pattern Mining) example "in action" :)
#Install the R package arules if required
#install.packages("arules");
#load the arules package
library("arules");
# read the transaction file as a Transaction class
txn = read.transactions(file="d:\\work\\R\\items.csv", rm.duplicates= FALSE, format="basket",sep=",");
#To visualize the item frequency in txn file
itemFrequencyPlot(txn);
# Run the apriori algorithm
basket_rules <- apriori(txn,parameter = list(sup = 0.2, conf = 0.9,target="rules"));
# Check the generated rules using inspect
inspect(basket_rules);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment