-
Notifications
You must be signed in to change notification settings - Fork 27
/
2013-04-05-Frequent-Pattern.html
480 lines (376 loc) · 13.5 KB
/
2013-04-05-Frequent-Pattern.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>2013-04-05-Frequent-Pattern</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="title" content="2013-04-05-Frequent-Pattern"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2013-04-05 00:56:49 PDT"/>
<meta name="author" content="Jim Blomo"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<link rel="stylesheet" type="text/css" href="production/common.css" />
<link rel="stylesheet" type="text/css" href="production/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="production/projection.css" media="projection" />
<link rel="stylesheet" type="text/css" href="production/color-blue.css" media="projection" />
<link rel="stylesheet" type="text/css" href="production/presenter.css" media="presenter" />
<link href='http://fonts.googleapis.com/css?family=Lobster+Two:700|Yanone+Kaffeesatz:700|Open+Sans' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="preamble">
</div>
<div id="content">
<h1 class="title">2013-04-05-Frequent-Pattern</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Frequent Patterns</a></li>
<li><a href="#sec-2">2 Finding Patterns</a>
<ul>
<li><a href="#sec-2-1">2.1 Patterns</a></li>
</ul>
</li>
<li><a href="#sec-3">3 Market Basket</a>
<ul>
<li><a href="#sec-3-1">3.1 Details</a></li>
</ul>
</li>
<li><a href="#sec-4">4 Define "Frequently"</a>
<ul>
<li><a href="#sec-4-1">4.1 Probabilities</a></li>
</ul>
</li>
<li><a href="#sec-5">5 Minimums</a>
<ul>
<li><a href="#sec-5-1">5.1 "Frequently"</a></li>
</ul>
</li>
<li><a href="#sec-6">6 Too Many Rules</a></li>
<li><a href="#sec-7">7 Subset Patterns</a>
<ul>
<li><a href="#sec-7-1">7.1 Shortcut</a></li>
</ul>
</li>
<li><a href="#sec-8">8 Apriori</a></li>
<li><a href="#sec-9">9 :slide:</a>
<ul>
<li><a href="#sec-9-1">9.1 Speed</a></li>
</ul>
</li>
<li><a href="#sec-10">10 Interesting Patterns</a>
<ul>
<li><a href="#sec-10-1">10.1 Details</a></li>
</ul>
</li>
<li><a href="#sec-11">11 Lift</a>
<ul>
<li><a href="#sec-11-1">11.1 Correlation</a></li>
</ul>
</li>
<li><a href="#sec-12">12 <b>Break</b></a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> Frequent Patterns <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-1">
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Finding Patterns <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-2">
<ul>
<li>Cookies frequently purchased with milk
</li>
<li>Website signups frequently occurring after reading FAQ
</li>
<li>DNA sections frequently seen with a drug reaction
</li>
</ul>
</div>
<div id="outline-container-2-1" class="outline-3">
<h3 id="sec-2-1"><span class="section-number-3">2.1</span> Patterns <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-2-1">
<ul>
<li>set of items
</li>
<li>subsequences of actions
</li>
<li>substructures
</li>
<li>Generalized to any kind of pattern that occurs "frequently" in the dataset
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3"><span class="section-number-2">3</span> Market Basket <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-3">
<ul>
<li>What things are frequently purchased together?
</li>
<li>Apocryphal example: beer and diapers
</li>
<li>Can be used for any natural grouping
</li>
</ul>
</div>
<div id="outline-container-3-1" class="outline-3">
<h3 id="sec-3-1"><span class="section-number-3">3.1</span> Details <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-3-1">
<ul>
<li>Example of how patterns are discovered is to look at groups of actions
</li>
<li>One natural group is the shopping basket: what items are in it?
</li>
<li>But can also be applied to anytime there is a natural grouping
<ul>
<li>Eg. web session logs group naturally around a person and time window
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4"><span class="section-number-2">4</span> Define "Frequently" <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-4">
<dl>
<dt>Action</dt><dd><code>A</code> and <code>B</code>
</dd>
<dt>Support</dt><dd>probability that a transaction contains <code>A ∪ B</code>
</dd>
<dt>Confidence</dt><dd>conditional probability that a transaction having <code>A</code> also
contains <code>B</code>
</dd>
</dl>
</div>
<div id="outline-container-4-1" class="outline-3">
<h3 id="sec-4-1"><span class="section-number-3">4.1</span> Probabilities <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-4-1">
<ul>
<li>We have two actions <code>A</code> and <code>B</code>
</li>
<li>Out of all the groupings, how many had both items?
</li>
<li>Out of all the groupings with <code>A</code>, how many had <code>B</code>?
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-5" class="outline-2">
<h2 id="sec-5"><span class="section-number-2">5</span> Minimums <span class="tag"><span class="slide">slide</span> <span class="two_col">two_col</span></span></h2>
<div class="outline-text-2" id="text-5">
<dl>
<dt>Min Support</dt><dd>lower bound on support probability
</dd>
<dt>Min Confidence</dt><dd>lower bound on confidence probability
</dd>
<dt>Strong</dt><dd>Rule that satisfies both minimums
</dd>
</dl>
<p> <img src="img/strawberry-milk.jpg" alt="img/strawberry-milk.jpg" />
</p>
</div>
<div id="outline-container-5-1" class="outline-3">
<h3 id="sec-5-1"><span class="section-number-3">5.1</span> "Frequently" <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-5-1">
<ul>
<li>Now we can talk about what frequently means
</li>
<li>It doesn't matter if two very unpopular items were purchased together: car
battery and smoke detector
</li>
<li>Also don't care if <code>A</code> happens a lot: everybody buys milk, so not a big
deal if some bought milk and strawberries
</li>
<li>Also important to note confidence is not symmetric: buying strawberries may be
frequent with buying milk, but not visa versa
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-6" class="outline-2">
<h2 id="sec-6"><span class="section-number-2">6</span> Too Many Rules <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-6">
<ul>
<li>Patterns not limited to 2 events
</li>
<li>But looking for all patterns leads to combinatorial number of options
</li>
</ul>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col class="left" />
</colgroup>
<tbody>
<tr><td class="left">a,b,c,d,e</td></tr>
<tr><td class="left">a,b</td></tr>
<tr><td class="left">a,c</td></tr>
<tr><td class="left">…</td></tr>
<tr><td class="left">a,b,c</td></tr>
<tr><td class="left">a,b,e</td></tr>
<tr><td class="left">…</td></tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-7" class="outline-2">
<h2 id="sec-7"><span class="section-number-2">7</span> Subset Patterns <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-7">
<dl>
<dt>Max-Pattern</dt><dd><code>X</code> rule is frequent and there exists no frequent
super-pattern <code>Y</code>
</dd>
<dt>Closed</dt><dd><code>X</code> rule is frequent and there exists no super-pattern <code>Y</code> <b>with the same support</b>
</dd>
<dt>Shortcut</dt><dd>Find only max-pattern or closed patterns, let other patterns be
subsets
</dd>
</dl>
</div>
<div id="outline-container-7-1" class="outline-3">
<h3 id="sec-7-1"><span class="section-number-3">7.1</span> Shortcut <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-7-1">
<ul>
<li>So how can we calculate all the potentially frequently occurring patterns?
</li>
<li>We can find either the max or closed pattern that encompasses all of the
patterns we're looking for
</li>
<li>These are more easily tracked, and we can still derive all of the
frequently occurring sub-patterns
</li>
<li>We can use the reverse: if a rule or item is not frequent enough alone, its
super-set will not be frequent enough:
<ul>
<li>If <code>A</code> is does not meet min support, there's no way for <code>A,B</code> to make
support
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-8" class="outline-2">
<h2 id="sec-8"><span class="section-number-2">8</span> Apriori <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-8">
<ol>
<li>Find supported single event rules
</li>
<li>Combine to make 2-event rules, check DB for support
</li>
<li>Combine to make 3-event rules, check DB…
</li>
<li>Stop when no N-event rules
</li>
</ol>
</div>
</div>
<div id="outline-container-9" class="outline-2">
<h2 id="sec-9"><span class="section-number-2">9</span> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-9">
<p> <img src="img/apriori.png" alt="img/apriori.png" />
</p>
</div>
<div id="outline-container-9-1" class="outline-3">
<h3 id="sec-9-1"><span class="section-number-3">9.1</span> Speed <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-9-1">
<ul>
<li>Isn't that slow? Yes!
</li>
<li>Book has some techniques to speed it up, mostly around grouping
</li>
<li>Can group together sets and if the group does not meet the support
threshold, then none of the members do
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-10" class="outline-2">
<h2 id="sec-10"><span class="section-number-2">10</span> Interesting Patterns <span class="tag"><span class="slide">slide</span> <span class="two_col">two_col</span></span></h2>
<div class="outline-text-2" id="text-10">
<ul>
<li>Strong rules may not always be interesting rules
</li>
<li>Basketball => eat cereal [40%, 66.7%] is strong
</li>
<li>But "not cereal" has a bigger effect on if you play basketball
</li>
</ul>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col class="left" /><col class="right" /><col class="right" /><col class="right" />
</colgroup>
<tbody>
<tr><td class="left"></td><td class="right">Basketball</td><td class="right">Not basketball</td><td class="right">Sum</td></tr>
<tr><td class="left">Cereal</td><td class="right">2000</td><td class="right">1750</td><td class="right">3750</td></tr>
<tr><td class="left">Not cereal</td><td class="right">1000</td><td class="right">250</td><td class="right">1250</td></tr>
<tr><td class="left">Sum</td><td class="right">3000</td><td class="right">2000</td><td class="right">5000</td></tr>
</tbody>
</table>
</div>
<div id="outline-container-10-1" class="outline-3">
<h3 id="sec-10-1"><span class="section-number-3">10.1</span> Details <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-10-1">
<ul>
<li>Not cereal column: has a huge effect on if someone plays basketball
</li>
<li>cereal + basketball… sure it happens frequently, but you'd actually
expect to see a bigger effect
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-11" class="outline-2">
<h2 id="sec-11"><span class="section-number-2">11</span> Lift <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-11">
<ul>
<li><code>P(A ∪ B) / P(A)*P(B)</code>
</li>
<li>If <code>A</code> and <code>B</code> independent, what is likelihood of <code>A</code> and <code>B</code>?
</li>
</ul>
</div>
<div id="outline-container-11-1" class="outline-3">
<h3 id="sec-11-1"><span class="section-number-3">11.1</span> Correlation <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-11-1">
<ul>
<li>1
</li>
<li>so if lift > 1, you're seeing something that is happening more often than
random
</li>
<li>< 1 means they negatively correlated
</li>
<li>X<sup>2</sup>, cosine, others in book
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-12" class="outline-2">
<h2 id="sec-12"><span class="section-number-2">12</span> <b>Break</b> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-12">
<script type="text/javascript" src="production/org-html-slideshow.js"></script>
</div>
</div>
</div>
<div id="postamble">
<p class="date">Date: 2013-04-05 00:56:49 PDT</p>
<p class="author">Author: Jim Blomo</p>
<p class="creator">Org version 7.8.02 with Emacs version 23</p>
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
</div>
</body>
</html>