0% found this document useful (0 votes)
144 views

Session8 PDF

The document discusses the Apriori algorithm for mining frequent itemsets from transactional data. It begins with key concepts of the Apriori algorithm such as frequent itemsets, join and apriori properties. It then walks through an example application of the Apriori algorithm on sample transaction data in multiple steps - generating frequent 1-itemsets, 2-itemsets, 3-itemsets and association rules. The document concludes with generating association rules from the frequent itemsets.

Uploaded by

Manvendra Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

Session8 PDF

The document discusses the Apriori algorithm for mining frequent itemsets from transactional data. It begins with key concepts of the Apriori algorithm such as frequent itemsets, join and apriori properties. It then walks through an example application of the Apriori algorithm on sample transaction data in multiple steps - generating frequent 1-itemsets, 2-itemsets, 3-itemsets and association rules. The document concludes with generating association rules from the frequent itemsets.

Uploaded by

Manvendra Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 94

Business Analytics

Today Objective

ENHANCING DECISION MAKING


Association Analytics : A mining
Approach

Indian Institute of Management (IIM),Rohtak


The Apriori Procedures
The Apriori Method is an influential method for
mining frequent item sets.

Key Concepts :
• Frequent Itemsets: The sets of item
which has minimum support (denoted
by Li for ith-Itemset).
• Join Operation: To find Lk , a set of
candidate k-itemsets is generated by
joining Lk with itself.
• Apriori Property: Any subset of
frequent itemset must be frequent.
Indian Institute of Management (IIM),Rohtak
Understanding Apriori through an Example

TID List of Items


• Consider a database, D , consisting
of 9 transactions.
T100 I1, I2, I5
• Suppose min. support count
T101 I2, I4
required is 2 (i.e. min_sup = 2/9 =
T102 I2, I3 22 % )
T103 I1, I2, I4 • Let minimum confidence required
is 70%.
T104 I1, I3
• We have to first find out the
T105 I2, I3 frequent itemset using Apriori
T106 I1, I3 algorithm.
T107 I1, I2 ,I3, I5 • Then, Association rules will be
generated using min. support &
T108 I1, I2, I3 min. confidence.

Indian Institute of Management (IIM),Rohtak


Step 1: Generating 1-itemset Frequent Pattern
Itemset Sup.Count Itemset Sup.Count
Compare candidate
Scan D for {I1} 6 support count with {I1} 6
count of each minimum support
candidate {I2} 7 {I2} 7
count
{I3} 6 {I3} 6
{I4} 2 {I4} 2
{I5} 2 {I5} 2

C1 L1

• In the first iteration of the algorithm, each item is a


member of the set of candidate.
• The set of frequent 1-itemsets, L1 , consists of the
candidate 1-itemsets satisfying minimum support.
Indian Institute of Management (IIM),Rohtak
Step 2: Generating 2-itemset Frequent Pattern
Itemset Sup.Count
{I1} 6
{I2} 7
{I3} 6
{I4} 2
{I5} 2

Itemset Itemset Sup. Itemset Sup


Compare
Generate {I1, I2} Scan D for Count candidate Count
C2 count of {I1, I2} 4 support count {I1, I2} 4
candidates {I1, I3} each with
from L1 {I1, I4} candidate {I1, I3} 4 minimum {I1, I3} 4
support count
{I1, I5} {I1, I4} 1 {I1, I5} 2

{I2, I3} {I1, I5} 2 {I2, I3} 4

{I2, I4} {I2, I4} 2


{I2, I3} 4
{I2, I5} {I2, I5} 2
{I2, I4} 2
{I3, I4} {I2, I5} 2 L2
{I3, I5}
{I3, I4} 0
{I4, I5}
{I3, I5} 1
C2 {I4, I5} 0

C2
Indian Institute of Management (IIM),Rohtak
Step 3: Generating 3-itemset Frequent Pattern
Itemset Sup
Generate candidate set C3 using L2 (join step).
Count
{I1, I2} 4
Condition of joining Lk-1 and Lk-1 is that it should
{I1, I3} 4 have (K-2) elements in common. So here, for L2,
{I1, I5} 2 first element should match.
{I2, I3} 4 •The generation of the set of candidate 3-
{I2, I4} 2 itemsets, C3 , involves use of the Apriori
{I2, I5} 2
Property.
•C3 = L2 Join L2={{I1, I2, I3},{I1, I2, I5},{I1, I3, I5},{I2, I3, I4}, {I2, I3, I5},{I2, I4,I5}}.
If we go for all
•C3 = L2 Join L2 = {{I1, I2, I3}, {I1, I2, I5}, {I1, I2, I4},
{I1, I3, I5}, {I2, I3, I4}, {I2, I3, I5}, {I2, I4, I5}}.
•Now, Join step is complete and Prune step will be used to
reduce the size of C3. Prune step helps to avoid heavy
computation due to large Ck.
Indian Institute of Management (IIM),Rohtak
Step 3: Generating 3-itemset Frequent Pattern

Compare
Scan D for Scan D for Itemset Sup. candidate Itemset Sup
count of Itemset count of support count
Count with min
Count
each each
candidate {I1, I2, I3} candidate {I1, I2, I3} 2 support count {I1, I2, I3} 2
{I1, I2, I5} {I1, I2, I5} 2
{I1, I2, I5} 2
C3 C3 L3

Generate candidate set C4 using L3 (join step). Condition


of joining Lk-1 and Lk-1 (K=4) is that, they should have (K-2)
elements in common. So here, for L3, first 2 elements
(items) should match.

Indian Institute of Management (IIM),Rohtak


Step 4: Generating 4-itemset Frequent Pattern
• The algorithm uses L3 Join L3 to generate a candidate
set of 4-itemsets, C4. Although the join results in {{I1,
I2, I3, I5}}, this itemset is pruned since its subset {{I2,
I3, I5}} is not frequent.
• Thus, C4 = φ , and procedure terminates, having
found all of the frequent items. This completes our
Apriori Algorithm.
• What’s Next ?
These frequent itemsets will be used to generate
strong association rules ( where strong association
rules satisfy both minimum support & minimum
confidence).

Indian Institute of Management (IIM),Rohtak


Step 5: Generating Association Rules from Frequent
Itemsets
• Procedure:
• For each frequent itemset “l”, generate all nonempty subsets of l.
• For every nonempty subset s of l, output the rule “s  (l-s)” if
support_count(l) / support_count(s) >= min_conf where
min_conf is minimum confidence threshold.

• Back To Example:
We had L = {{I1}, {I2}, {I3}, {I4}, {I5}, {I1,I2}, {I1,I3}, {I1,I5}, {I2,I3}, {I2,I4},
{I2,I5}, {I1,I2,I3}, {I1,I2,I5}}.
– Lets take l = {I1,I2,I5}.
– Its all nonempty subsets are {I1,I2}, {I1,I5}, {I2,I5}, {I1}, {I2}, {I5}.

• Let confidence threshold is , say 100%.


• The resulting association rules are shown below, each listed with its
confidence.

Indian Institute of Management (IIM),Rohtak


An Example :

Q1.A database has four transactions .


Let min_sup=70%(LET SAY 3),and min_conf=100%.
TID Date item_ bought
T100 10/15/99 {K, A, D, B}
T200 10/15/99 {D, A, C, E, B}
T300 10/19/99 {C, A, B, E}
T400 10/22/99 {B, A, D}

Indian Institute of Management (IIM),Rohtak


An Example :
C1 L1
Q1.A database has four transactions . A 4 A 4 AB 4
Let min_sup=70%(LET SAY 3),and B 4 B 4 AD 3
min_conf=100%.
TID Date item_ bought C 2 C 2 BD 3
T100 10/15/99 {K, A, D, B} D 3 D 3
T200 10/15/99 {D, A, C, E, B} E 2 E 2
T300 10/19/99 {C, A, B, E} ABD 3
T400 10/22/99 {B, A, D} K 1 K 1

Therefor ,the set of all frequent item sets are {A},{B},{D},{A B},{A
D},{B D},{A B D}

Indian Institute of Management (IIM),Rohtak


Simulation

Indian Institute of Management (IIM),Rohtak


Association Mining

The Titanic Dataset


• The Titanic dataset is a 4-dimensional table
with summarized information on the fate of
passengers on the Titanic according to
social class, sex, age and survival.
• To make it suitable for association rule
mining, save the “titanic.csv” in Documents
folder (the working directory)
• Load the Dataset:
titanic <- read.csv("titanic.csv", header=T)
Indian Institute of Management (IIM),Rohtak
Association Mining
View the uploaded data
>titanic

Indian Institute of Management (IIM),Rohtak


Association Mining
Summary of dataset
summary(titanic)

The summary shows the number of


categorical variables for each column

Indian Institute of Management (IIM),Rohtak


Association Mining

Installing package arules

• Provides the infrastructure for representing,


manipulating and analyzing transaction data and
patterns (frequent itemsets and association rules).
• Go to Packages tab in Output/Packages pane in
Rstudio
• Click on Install button
• Write arules in the Packages checkbox and click
on Install button

Indian Institute of Management (IIM),Rohtak


Association Mining
Installing arules package

Indian Institute of Management (IIM),Rohtak


Association Mining
Download completed

Indian Institute of Management (IIM),Rohtak


Association Mining
Visualizing Association Rules
Install arulesViz package(for graph and other
analysis)

After installation, load the package.


library(arulesViz)
Indian Institute of Management (IIM),Rohtak
Association Mining
Load arules package

Either click on the checkbox of arules package in the


Packages tab or write library(arules) in the R Console

Indian Institute of Management (IIM),Rohtak


Association Mining

Creating Association Rules


rules.all <- apriori(titanic)

The minimum support threshold is 0.1 and


minimum confidence is 0.8 by default
Indian Institute of Management (IIM),Rohtak
Association Mining

The Apriori algorithm generated 27 rules with the given constraints. Lets dive into the
Parameter Specification section of the output.
•minval is the minimum value of the support an itemset should satisfy to be a part of
a rule.
•smax is the maximum support value for an itemset.
•arem is an Additional Rule Evaluation Parameter. In the above code we have
constrained the number of rules using Support and Confidence. There are several
other ways to constrain the rules using the arem parameter in the function and we
will discuss more about it later in the session.
•aval is a logical indicating whether to return the additional rule evaluation measure
selected with arem.
•originalSupport The traditional support value only considers both LHS and RHS
items for calculating support. If you want to use only the LHS items for the
calculation then you need to set this to FALSE.
•maxtime is the maximum amount of time allowed to check for subsets.
•minlen is the minimum number of items required in the rule.
•maxlen is the maximum number of items that can be present in the rule.

Indian Institute of Management (IIM),Rohtak


Association Mining

Indian Institute of Management (IIM),Rohtak


Association Mining

What is the difference between lift and leverage?


Both lift and leverage measure the relation between the
probability of a given rule to occur (support(A→C)) and its
expected probability if the items were independent
(coverage(A)*coverage(C)) of each other. The only difference
is that lift computes the ratio of both factors
(support(A→C)/(coverage(A)*coverage(C))) and leverage
computes the difference (support(A→C)-
(coverage(A)*coverage(C))). The implications are that lift may
find very strong associations for less frequent items, while
leverage tends to prioritize items with higher
frequencies/support in the dataset.

Indian Institute of Management (IIM),Rohtak


Association Mining
Inspecting the rules created
inspect(rules.all) #shows all the rules created with given criteria

The default value in


parameter for minlen is 1.
This means that rules with
only one item (i.e., an empty
antecedent/LHS) like
{} => {age=adult} will be
created.
These rules mean that no
matter what other items are
involved the item in the RHS
will appear with the
probability given by the rule's
confidence (which equals the
support).
If you want to avoid these
rules then use the argument
parameter=list(minlen=2)
Indian Institute of Management (IIM),Rohtak
Association Mining
Inspecting the rules created
rules.all =sort(rules.all, by="lift") #sort as per lift value
inspect(rules.all)

Indian Institute of Management (IIM),Rohtak


Association Mining

Question 1: Show rules containing “Survived” only in the RHS


rules <- apriori(titanic, parameter = list(minlen=2, supp=0.005, conf=0.8),
appearance = list(rhs=c("Survived=No", "Survived=Yes"), default="lhs"))

Indian Institute of Management (IIM),Rohtak


Association Mining
Question 1: Show rules containing “Survived” only in the RHS
inspect(rules)

Indian Institute of Management (IIM),Rohtak


Association Mining

Question 2: keep the confidence, support, and lift


values to three decimal places
quality(rules) <- round(quality(rules), digits=3)
inspect(rules)

Indian Institute of Management (IIM),Rohtak


Association Mining

Question 3: Order the rules by lift


rules.sorted <- sort(rules, by="lift")
inspect(rules.sorted)

Indian Institute of Management (IIM),Rohtak


Association Mining
Question 4: Show the rules of survived adults and
children of 1st, 2nd, and 3rd class
• rules <- apriori(titanic, parameter = list(minlen=3,
supp=0.002, conf=0.2), appearance =
list(default="none", rhs=c("Survived=Yes"),
lhs=c("Class=1st", "Class=2nd", "Class=3rd",
"Age=Child", "Age=Adult"))) #specifying both
the LHS and RHS, and hence default="none“
(with out default also work)
• rules.sorted <- sort(rules, by="confidence")
• inspect(rules.sorted)
Indian Institute of Management (IIM),Rohtak
Association Mining

Indian Institute of Management (IIM),Rohtak


Association Mining

Visualizing Association Rules

After installation, load the package.


library(arulesViz)
Indian
Indian Institute
Institute of Management
of Management (IIM),Rohtak
Rohtak
Association Mining
plot(rules.sorted) Plotting rules
# This visualization method draws a two dimensional scatterplot with
different measures of interestingness (parameter "measure") on the axes
and a third measure (parameter "shading") is represented by the color of
the points.

Indian Institute of Management (IIM),Rohtak


Association Mining
Grouped matrix for rules
plot(rules.sorted, method = "grouped")

Indian Institute of Management (IIM),Rohtak


Association Mining
Grouped matrix for rules
plot(rules.all, method = "grouped")
#Antecedents (columns) in the matrix are grouped using
clustering. Balloons in the matrix are used to represent
with what consequent the antecedents are connected.

Indian Institute of Management (IIM),Rohtak


Association Mining
Graph based visualization
plot(rules.sorted, method="graph", control=list(type="items"))
or
plot(rules.sorted, method="graph")
#Represents the rules (or itemsets) as a graph

Indian Institute of Management (IIM),Rohtak


Association Mining
Graph based visualization
plot(rules.all, method="graph", control=list(type="items"))

Indian Institute of Management (IIM),Rohtak


Association Mining
Parallel coordinates plot
plot(rules.sorted, method="paracoord", control=list (reorder=TRUE) )
#Represents the rules (or itemsets) as a parallel coordinate plot.

Indian Institute of Management (IIM),Rohtak


Association Mining

Indian Institute of Management (IIM),Rohtak


Association Mining

https://towardsdatascience.com/a-
gentle-introduction-on-market-
basket-analysis-association-rules-
fa4b986a40ce

Indian Institute of Management (IIM),Rohtak


Association Mining

items.csv

Indian Institute of Management (IIM),Rohtak


Association Mining

Case(items.csv)
Question: Find the association rules with support = 0.22, and
confidence=0.7
Sol: Save the “items.csv” file in the working directory and load the data
item <- read.transactions("items.csv", format = "basket", sep = ",")
summary(item)
Note: read.transaction requires “arules” package to be installed and
loaded

http://www.learnbymarketin
g.com/1043/working-with-
arules-transactions-and-
read-transactions/

Indian Institute of Management (IIM),Rohtak


Association Mining

Mining rules (items.csv)


• rules.all <- apriori(item, parameter =
list(minlen=2, supp=0.22, conf=0.7))
• inspect(rules.all)

Indian Institute of Management (IIM),Rohtak


Association Mining

plot(rules.all, method="graph", control=list(type="items"))

Indian Institute of Management (IIM),Rohtak


Association Mining
Case(transactions.csv)
Question: Find the association rules with support =
0.7, and confidence=100%
Sol: Save the “transactions.csv” file in the working directory and
load the data
item <- read.transactions("transactions.csv", format = "basket", sep =
",")
summary(item)
Note: read.transaction requires “arules” package to be installed and
loaded

Indian Institute of Management (IIM),Rohtak


Association Mining

Mining rules (transactions.csv)


• rules.all <- apriori(item, parameter =
list(minlen=2, supp=0.7, conf=1))
• inspect(rules.all)

Indian Institute of Management (IIM),Rohtak


Association Mining

Case(supermarket.csv)
Question: Find the association rules with support = 0.4, and
confidence=0.95
Sol: Save the file in Documents folder (working directory)
Load the data:
• supermarket <- read.transactions("supermarket.csv",
format = "basket", sep = ",")
• summary(supermarket)
Note: format = "basket" is when you have multiple data
items
Mining the rules
• rules.all <- apriori(supermarket, parameter =
list(minlen=2, supp=0.22, conf=0.7))
• inspect(rules.all)
Indian Institute of Management (IIM),Rohtak
Association Mining

Indian Institute of Management (IIM),Rohtak


Association Mining
Case(groceries.csv)
Display first three transaction

Print Frequency plot of TOP 10 item

Display item which support .15

Generate top 5 rule based on given support(.5) and confidence(.9)

Sort top four rule based upon lift value

Indian Institute of Management (IIM),Rohtak


Association Mining

groceries1 <- read.transactions("groceries.csv",


format = "basket", sep = ",")

summary(groceries1)
transactions as itemMatrix in sparse format with
9835 rows (elements/itemsets/transactions) and
169 columns (items) and a density of 0.02609146

most frequent items:


whole milk other vegetables rolls/buns soda yogu
rt
2513 1903 1809 1715 1372
(Other)
34055

inspect(groceries1)
Indian Institute of Management (IIM),Rohtak
Association Mining
Case(groceries.csv)
Display first three transaction

Print Frequency plot of TOP 10 item

Display item which support .15

Generate top 5 rule based on given support(.5) and confidence(.9)

Sort top four rule based upon lift value

Indian Institute of Management (IIM),Rohtak


Association Mining

Display first three transaction

inspect(groceries1[1:3])

items
[1] {citrus fruit,margarine,ready so
ups,semi-finished bread}
[2] {coffee,tropical fruit,yogurt}
[3] {whole milk}

Indian Institute of Management (IIM),Rohtak


Association Mining
Case(groceries.csv)
Display first three transaction

Print Frequency plot of TOP 10 item

Display item which support .15

Generate top 5 rule based on given support(.5) and confidence(.9)

Sort top four rule based upon lift value

Indian Institute of Management (IIM),Rohtak


Association Mining

Print Frequency plot of TOP 10 item

itemFrequencyPlot(groceries1,topN=10)

Indian Institute of Management (IIM),Rohtak


Association Mining
Case(groceries.csv)
Display first three transaction

Print Frequency plot of TOP 10 item

Display item which support .15

Generate top 5 rule based on given support(.5) and confidence(.9)

Sort top four rule based upon lift value

Indian Institute of Management (IIM),Rohtak


Association Mining

Display item which support .15

itemFrequencyPlot(groceries1,support=.15)

Indian Institute of Management (IIM),Rohtak


Association Mining
Case(groceries.csv)
Display first three transaction

Print Frequency plot of TOP 10 item

Display item which support .15

Generate top 5 rule based on given support(.5) and confidence(.9)

Sort top four rule based upon lift value

Indian Institute of Management (IIM),Rohtak


Association Mining
Generate top 5 rule based on given support(.5) and confidence(.9)
m1<-apriori(groceries1,parameter = list(support=.5,confidence=.9))
inspect(m1)
summary(m1)
Set of 0 rule
Change values(.005) and (.25)
m1<-apriori(groceries1,parameter = list(support=.5,confidence=.9))
inspect(m1)
summary(m1)
Set of 663 rule
inspect(m1[1:5])
lhs rhs support confidence lift
[1] {} => {whole milk} 0.255516014 0.2555160 1.000000
[2] {cake bar} => {whole milk} 0.005592272 0.4230769 1.655775
[3] {dishes} => {other vegetables} 0.005998983 0.3410405 1.762550
[4] {dishes} => {whole milk} 0.005287239 0.3005780 1.176357
[5] {mustard} => {whole milk} 0.005185562 0.4322034 1.691492
Indian Institute of Management (IIM),Rohtak
Association Mining
Case(groceries.csv)
Display first three transaction

Print Frequency plot of TOP 10 item

Display item which support .15

Generate top 5 rule based on given support(.5) and confidence(.9)

Sort top four rule based upon lift value

Indian Institute of Management (IIM),Rohtak


Association Mining

inspect(sort(m1,by="lift")[1:4])
lhs rhs support confidence
[1] {citrus fruit,other vegetables,whole milk} => {root vegetables} 0.005795628
0.4453125
[2] {butter,other vegetables} => {whipped/sour cream} 0.005795628
0.2893401
[3] {herbs} => {root vegetables} 0.007015760 0.4312500
[4] {citrus fruit,pip fruit} => {tropical fruit} 0.005592272 0.4044118
lift
[1] 4.085493
[2] 4.036397
[3] 3.956477
[4] 3.854060

Indian Institute of Management (IIM),Rohtak


Association Mining

Indian Institute of Management (IIM),Rohtak


Association Mining

Rattle
• Rattle (the R Analytical Tool To Learn
Easily) is a graphical data mining application
built upon the statistical language R
• It provides a Graphical User Interface (GUI)
for easier use
• It is used for data mining and statistical model
building
https://rattle.togaware.com/

Indian Institute of Management (IIM),Rohtak


Association Mining

Installing rattle
• Before installing rattle, you need to install RGtk2
package
• In the R console type
install.packages("https://cran.r-
project.org/bin/windows/contrib/3.3/RGtk2_2.20.31.
zip", repos=NULL)
• Install rattle
install.packages("rattle")
• Load rattle
library(rattle)
Indian Institute of Management (IIM),Rohtak
Association Mining

Rattle GUI
• rattle() # This will open the Rattle GUI

Indian Institute of Management (IIM),Rohtak


Association Mining
Load the dataset
• Save the “supermarket_rattle.csv” file in the Documents
folder
• Go to the Rattle GUI
• Go to the Data tab
• Select Source as spreadsheet
• Keep the Separator as “,” and select the Header
checkbox
• Click on the File Name browsing option
• Select the “supermarket_rattle.csv” file from browse
option and click on the Open button

Indian Institute of Management (IIM),Rohtak


Association Mining
Load the dataset

Select the file from browse

Click

Indian Institute of Management (IIM),Rohtak


Association Mining
Preparing the data
Once you select the file, click on the execute button

Indian Institute of Management (IIM),Rohtak


Association Mining
Data preparation
The ID column is termed as Ident and Item column as Category

Indian Institute of Management (IIM),Rohtak


Association Mining
• Now go to the Associate tab
• Select Baskets checkbox
• Provide the support as 0.2 and Confidence as
0.95 and Min Length as 2
• Click on the Execute button

Indian Institute of Management (IIM),Rohtak


Association Mining

Association rule details

Other statistical measures

Indian Institute of Management (IIM),Rohtak


Association Mining

Frequency plot
• Click on the Freq Plot button in the Associate tab of Rattle GUI
• You can view the frequency plot in the Output tab of R studio

Indian Institute of Management (IIM),Rohtak


Association Mining

Object name <- read.csv(“Filename.csv")

# convert in to matrix format.


A1 <- as.matrix(Object name)

# Recast incidence matrix into transcations list.

A1.trans <- as(A1, "transactions")

Indian Institute of Management (IIM),Rohtak


Association Mining

Coursetopics.csv

Indian Institute of Management (IIM),Rohtak


Association Mining
# convert in to matrix format.
course.df <- read.csv("Coursetopics.csv")
course.mat <- as.matrix(course.df)
course.mat
# Recast matrix into transcations list.
course.trans <- as(course.mat, "transactions")
inspect(course.trans)
itemFrequencyPlot(course.trans)

Indian Institute of Management (IIM),Rohtak


Association Mining

# Generate rules with the highest lift.


rules <- apriori(course.trans, parameter = list(supp= 0.01, conf = 0.1,
target = "rules"))
inspect(head(sort(rules, by = "lift")))

Indian Institute of Management (IIM),Rohtak


Association Mining
CATLOG CROSS –SELLING
catalog.df <- read.csv("CatalogCrossSell.csv")
# dataframe to matrix
catalog.mat <- as.matrix(catalog.df[,-1])
View(catalog.mat)
# matrix to transcations
catalog.trans <- as(catalog.mat, "transactions")
itemFrequencyPlot(catalog.trans)

Indian Institute of Management (IIM),Rohtak


Association Mining
# Generate rules
liftrules <- apriori(catalog.trans, parameter = list(supp= 0.1, conf = 0.5,
target = "rules"))
inspect(head(sort(rules, by = "lift")))

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


ORANGE
Image Analytics

Indian Institute of Management (IIM),Rohtak


ORANGE
Image Analytics

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


An Example :
C1 L1
Q1.A database has four transactions . A 4 A 4 AB 4
Let min_sup=70%(LET SAY 3),and B 4 B 4 AD 3
min_conf=100%.
TID Date item_ bought C 2 C 2 BD 3
T100 10/15/99 {K, A, D, B} D 3 D 3
T200 10/15/99 {D, A, C, E, B} E 2 E 2
T300 10/19/99 {C, A, B, E} ABD 3
T400 10/22/99 {B, A, D} K 1 K 1

Therefor ,the set of all frequent item sets are {A},{B},{D},{A B},{A
D},{B D},{A B D}

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


ORANGE

Leverage
leverage(X -> Y) = P(X and Y) - (P(X)P(Y))
Leverage measures the difference of X and Y appearing together in
the data set and what would be expected if X and Y where statistically
dependent. The rational in a sales setting is to find out how many
more units (items X and Y together) are sold than expected from the
independent sells. Using min. leverage thresholds at the same time
incorporates an implicit frequency constraint. E.g., for setting a min.
leverage thresholds to 0.01% (corresponds to 10 occurrence in a data
set with 100,000 transactions) one first can use an algorithm to find all
itemsets with min. support of 0.01% and then filter the found item sets
using the leverage constraint. Because of this property leverage also
can suffer from the rare item problem.
Indian Institute of Management (IIM),Rohtak
ORANGE

Item.csv

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


ORANGE

Now new data file :cosmetics.csv


65% support, generate rule

Indian Institute of Management (IIM),Rohtak


ORANGE

Indian Institute of Management (IIM),Rohtak


Code _Python

Indian Institute of Management (IIM),Rohtak


Thank you !!!
Indian Institute of Management (IIM),Rohtak

You might also like