Association analysis is one of the common parts of unsupervised machine learning.
In association analysis, our goal is briefly to find things happening together.
Look at this table of people puchasing items:
ID
Items
1
Milk, Bread
2
Butter
3
Beer, Tissue
4
Milk, Bread, Butter
5
Bread
You could probably find that milk and butter are always purchased together.
{Milk}→{Butter}
This is what we are tring to do through associate rule mining: exploring a set
of data (transactions) and output a kind of descriptive result (association rules).
Basic Concepts
Here are some basic concepts of associate rule mining:
Item: a label which appears in some records, such as Milk, Bread,...
Itemset: a collection of items, like: {Milk,Bread}.
Association rule: an ordered pair of itemsets, like: {Milk}→{Butter}
For given transactions T={t∣t is an itemset} with n distinct items, we define:
Support count: σ(x)=∣{t∈T∣t property contains x}∣,
where x is a itemset.
And two metrics to evalute how significant a rule r:x→y is:
Support: s(x→y)=∣T∣σ(x∪y)
Confidence: c(x→y)=σ(x)σ(x∪y)
Then, an Association Rule Mining Task could be defined as:
For given transactions T and thresholds minSup and minConf, find a set of rules:
R={x→y∣x∩y=∅∧s(x→y)≥minSup∧c(x→y)≥minConf}
There are
2n×2n possibilities of pair x and y. Simply enumerating
all possible rules could be expotential time complexity and it doesn't work
with a growing size of transactions.
As it's easy to know that:
∀r:x→y, if s(x→y)≥minSup,∣T∣σ(x∪y)≥minSup
For such kind of a=x∪y∣∣T∣σ(a)≥minSup,
we say a is a frequent itemset. And it could be better if we calculate all
posible frequent itemsets first.
Followed by this idea, the process of association rule mining could be divided
into two steps:
Find a collection of frequent itemsets I={a∣∣T∣σ(a)≥minSup}
For each a∈I, find all rules {r:x→(a−x)∣c(x→y)≥minConf}
Frequent Itemset Generation
There are many ways to calculate frequent itemsets. One of them is called
Apriori algorithm.
This algorithm is based on a pretty simple idea:
∀x⊆y,σ(x)≥σ(y), where x, y are two itemsets
So, if x isn't a frequent itemset, any super set of x could not be a frequent
item set. Apriori algorithm
uses this as prune strategy.
This algorithm starts with an empty set candidate frequent itemsets. Every time,
it expands one more item into candidate sets. And prune impossible candidates
immediately.
Flow Diagram
Pseudo code
Apriori(T,minSup)C←∅forx∈{distinct items of T}C←{x}∪I∪{x∪a∣a∈I}C←{a∣a∈C∧∣T∣σ(x))≥minSup}returnC
Rule Generation
Now, let's turn to the part of rule generation.
As it's easy to know:
∀x,y⊇z,c(x→y)=σ(y)σ(x)≥σ(y−z)σ(x∪z)≥c(x∩z,y−z)
So, for every r:x→y, if c(x→y)≥minConf, moving more
items from y to x doesn't change the requirement of minConf.
Using this as a prune strategy, we can get a simple rule generation algorithm.
Assogication rule mining could produce a huge number of rules. But not all of
them could be meaningful. Mostly we need more metrics to evalute generate rueles,
which are called interestingness measure.
Drawback of Confidence
Look at this example table of frequency:
xxy157590y55102080
As we know,
c(x→y)=σ(x)σ(x∪y)=2015=0.75
since 0.75 is sufficienty high, rule x→y seems to be a pretty significant
rule.
But really? P(y)=10090=0.9>0.75, which means X actually reduces
the possibility of Y.
Statistical Dependence
For any x and y:
If P(x,y)>P(x)×P(y), then we say x and y are positive related.
If P(x,y)<P(x)×P(y), then we say x and y are negative related.
Interestingness Measure
There are actually manu ways to measure interestingness of association rules,
but based on what we've talked before, one simple measure could be
(ϕ-coefficient):