Data Mining Learning from Large Data Sets Lecture 3 - - PowerPoint PPT Presentation

data mining
SMART_READER_LITE
LIVE PREVIEW

Data Mining Learning from Large Data Sets Lecture 3 - - PowerPoint PPT Presentation

Data Mining Learning from Large Data Sets Lecture 3 Locality Sensi7ve Hashing 263-5200-00L Andreas Krause Announcement No class next week


slide-1
SLIDE 1

Data ¡Mining ¡

Learning ¡from ¡Large ¡Data ¡Sets ¡

Lecture ¡3 ¡– ¡Locality ¡Sensi7ve ¡ Hashing ¡

¡ 263-­‑5200-­‑00L ¡ Andreas ¡Krause ¡

slide-2
SLIDE 2

Announcement ¡

No ¡class ¡next ¡week ¡

2 ¡

slide-3
SLIDE 3

Review: ¡

¡Fast ¡near ¡neighbor ¡search ¡

¡ ¡in ¡high ¡dimensions ¡

3 ¡

slide-4
SLIDE 4

Locality ¡sensi7ve ¡hashing ¡

Idea: ¡Create ¡hash ¡func7on ¡that ¡maps ¡“similar” ¡items ¡

to ¡same ¡bucket ¡ ¡

Key ¡problem: ¡Is ¡it ¡possible ¡to ¡construct ¡such ¡hash ¡

func7ons?? ¡

Depends ¡on ¡the ¡distance ¡func7on ¡ Possible ¡for ¡Jaccard ¡distance!! ¡J ¡ Some ¡other ¡distance ¡func7ons ¡work ¡as ¡well ¡ ¡

4 ¡

0 ¡ 1 ¡ 2 ¡ 3 ¡

Hashtable ¡

slide-5
SLIDE 5

Recall: ¡Shingle ¡Matrix ¡

5 ¡

¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡

documents ¡ shingles ¡

Sim(A, B) = |A ∩ B| |A ∪ B|

slide-6
SLIDE 6

Min-­‑hashing ¡

Simple ¡hash ¡func7on, ¡constructed ¡in ¡the ¡following ¡way: ¡ Use ¡random ¡permuta7on ¡π ¡to ¡reorder ¡the ¡rows ¡of ¡the ¡matrix

¡

Must ¡use ¡same ¡permuta7on ¡for ¡all ¡columns ¡C!! ¡

h(C) ¡= ¡minimum ¡row ¡number ¡in ¡which ¡permuted ¡column

¡ ¡ ¡ ¡ ¡contains ¡a ¡1 ¡

6 ¡

h(C) = hπ(C) = min

i:C(i)=1 π(i)

slide-7
SLIDE 7

Min-­‑hashing ¡property ¡

Want ¡that ¡similar ¡documents ¡(columns) ¡have ¡same ¡

value ¡of ¡hash ¡func7on ¡(with ¡high ¡probability) ¡

Turns ¡out ¡it ¡holds ¡that ¡ Need ¡to ¡control ¡false ¡posi7ves ¡and ¡misses. ¡

7 ¡

Pr[h(C1) = h(C2)] = Sim(C1, C2)

slide-8
SLIDE 8

Min-­‑hash ¡signatures ¡

8 ¡

Input ¡matrix ¡ ¡

¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 1 ¡ ¡ 3 4 7 6 1 2 5

Signature ¡matrix ¡M ¡

1 ¡ 2 ¡ 1 ¡ 2 ¡ 5 ¡ 7 ¡ 6 ¡ 3 ¡ 1 ¡ 2 ¡ 4 ¡ 1 ¡ 4 ¡ 1 ¡ 2 ¡ 4 ¡ 5 ¡ 2 ¡ 6 ¡ 7 ¡ 3 ¡ 1 ¡ 2 ¡ 1 ¡ 2 ¡ 1 ¡

Similari7es: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡1-­‑3 ¡ ¡ ¡ ¡ ¡ ¡2-­‑4 ¡ ¡ ¡ ¡1-­‑2 ¡ ¡ ¡3-­‑4 ¡ Col/Col ¡ ¡ ¡ ¡0.75 ¡ ¡ ¡ ¡0.75 ¡ ¡ ¡ ¡0 ¡ ¡ ¡ ¡ ¡ ¡ ¡0 ¡ Sig/Sig ¡ ¡ ¡ ¡ ¡0.67 ¡ ¡ ¡ ¡1.00 ¡ ¡ ¡ ¡ ¡0 ¡ ¡ ¡ ¡ ¡ ¡ ¡0 ¡

slide-9
SLIDE 9

Hashing ¡bands ¡of ¡M ¡

9 ¡

Matrix M r rows b bands

Buckets

slide-10
SLIDE 10

One ¡hash ¡func7on ¡

10 ¡

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 r=1 b=1 Similarity P(hash hit)

slide-11
SLIDE 11

100 ¡hash ¡func7ons ¡

11 ¡

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 r=10 b=10 Similarity P(hash hit)

slide-12
SLIDE 12

100 ¡hash ¡func7ons ¡

12 ¡

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 r=1 b=100 r=2 b=50 r=5 b=20 r=10 b=10 r=20 b=5 Similarity

slide-13
SLIDE 13

1000 ¡hash ¡func7ons ¡

13 ¡

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.2 0.4 0.6 0.8 1 r=1 b=1000 r=2 b=500 r=5 b=200 r=10 b=100 r=20 b=50 r=50 b=20 Similarity

slide-14
SLIDE 14

10000 ¡hash ¡func7ons ¡

14 ¡

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.2 0.4 0.6 0.8 1 r=1 b=10000 r=2 b=5000 r=5 b=2000 r=10 b=1000 r=20 b=500 r=50 b=200 Similarity

slide-15
SLIDE 15

LSH ¡more ¡generally ¡

So ¡far ¡we ¡have ¡considered ¡

Min-­‑hashing ¡for ¡compu7ng ¡compact ¡document ¡signatures ¡

represen7ng ¡Jaccard ¡similarity ¡

Locality ¡Sensi7ve ¡Hashing ¡(LSH) ¡for ¡decreasing ¡false ¡

nega7ves ¡and ¡false ¡posi7ves ¡

Let’s ¡us ¡do ¡duplicate ¡detec7on ¡without ¡requiring ¡pairwise ¡

comparisons! ¡

Can ¡we ¡generalize ¡what ¡we ¡learned? ¡

Other ¡data ¡types ¡(e.g., ¡real ¡vectors ¡è ¡images) ¡ Other ¡distance ¡func7ons ¡(Euclidean? ¡Cosine?) ¡

15 ¡

slide-16
SLIDE 16

Key ¡insight ¡behind ¡LSH ¡

LSH ¡allows ¡to ¡boost ¡the ¡gap ¡between ¡similar ¡

(Sim(C1,C2)>s) ¡non-­‑similar ¡(Sim(C1,C2)<s’ ¡for ¡s’ ¡< ¡s) ¡pairs ¡

16 ¡

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 r=1 b=1 Similarity P(hash hit) 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 r=10 b=10 Similarity P(hash hit)

slide-17
SLIDE 17

LSH ¡more ¡generally ¡

Consider ¡a ¡metric ¡space ¡(S,d), ¡and ¡a ¡family ¡F ¡of ¡hash ¡

func7ons ¡h: ¡SàB ¡

F ¡is ¡called ¡(d1, ¡d2, ¡p1, ¡p2)-­‑sensi5ve ¡if ¡ ¡

¡

17 ¡

∀x, y ∈ S : d(x, y) ≤ d1 ⇒ Pr[h(x) = h(y)] ≥ p1 ∀x, y ∈ S : d(x, y) ≥ d2 ⇒ Pr[h(x) = h(y)] ≤ p2

slide-18
SLIDE 18

Example ¡

18 ¡

P(hit) ¡ d ¡

slide-19
SLIDE 19

Example: ¡Jaccard-­‑distance ¡

Recall, ¡we ¡want: ¡

19 ¡

∀x, y ∈ S : d(x, y) ≤ d1 ⇒ Pr[h(x) = h(y)] ≥ p1 ∀x, y ∈ S : d(x, y) ≥ d2 ⇒ Pr[h(x) = h(y)] ≤ p2

slide-20
SLIDE 20

Boos7ng ¡a ¡LS ¡hash ¡family ¡

Can ¡we ¡reduce ¡false ¡posi7ves ¡and ¡false ¡nega7ves ¡(create ¡

“S-­‑curve ¡effect”) ¡for ¡arbitrary ¡LS ¡hash ¡func7ons?? ¡

Can ¡apply ¡same ¡par77oning ¡technique! ¡ AND/OR ¡construc7on ¡

20 ¡

slide-21
SLIDE 21

r-­‑way ¡AND ¡of ¡hash ¡func7on ¡

Goal: ¡Decrease ¡false ¡posi7ves ¡ Convert ¡hash ¡family ¡F ¡to ¡new ¡family ¡F’ ¡ Each ¡member ¡of ¡F’ ¡consists ¡of ¡a ¡“vector” ¡of ¡r ¡hash ¡

func7ons ¡from ¡F ¡

For ¡h ¡= ¡[h1,…,hr] ¡in ¡F’, ¡h(x)=h(y) ¡ó ¡hi(x)=hi(y) ¡for ¡all ¡i. ¡ Theorem: ¡Suppose ¡F ¡is ¡(d1,d2,p1,p2)-­‑sensi7ve. ¡ ¡

Then ¡F’ ¡is ¡( ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡)-­‑sensi7ve ¡

21 ¡

slide-22
SLIDE 22

b-­‑way ¡OR ¡of ¡hash ¡func7on ¡

Goal: ¡Decrease ¡false ¡nega7ves ¡ Convert ¡hash ¡family ¡F ¡to ¡new ¡family ¡F’ ¡ Each ¡member ¡of ¡F’ ¡consists ¡of ¡a ¡“vector” ¡of ¡b ¡hash ¡

func7ons ¡from ¡F ¡

For ¡h ¡= ¡[h1,…,hr] ¡in ¡F’, ¡h(x)=h(y) ¡ó ¡hi(x)=hi(y) ¡for ¡some ¡i. ¡ Theorem: ¡Suppose ¡F ¡is ¡(d1,d2,p1,p2)-­‑sensi7ve. ¡ ¡

Then ¡F’ ¡is ¡( ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡)-­‑sensi7ve ¡

22 ¡

slide-23
SLIDE 23

Composing ¡AND ¡and ¡OR ¡

Suppose ¡we ¡start ¡with ¡a ¡(d1,d2,p1,p2)-­‑sensi7ve ¡F ¡ First ¡apply ¡r-­‑way ¡AND, ¡then ¡b-­‑way ¡OR ¡ This ¡results ¡in ¡(d1,d2, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡) ¡sensi7ve ¡F’ ¡ Can ¡also ¡reverse ¡order ¡of ¡AND ¡and ¡OR ¡ This ¡results ¡in ¡(d1,d2, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡) ¡sensi7ve ¡F’ ¡

23 ¡

slide-24
SLIDE 24

Example ¡

24 ¡ 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

OR−AND AND−OR

slide-25
SLIDE 25

Cascading ¡construc7ons ¡

Can ¡also ¡combine ¡all ¡previous ¡construc7ons ¡ For ¡example, ¡first ¡apply ¡(4,4) ¡OR-­‑AND ¡construc7on ¡

followed ¡by ¡a ¡(4,4) ¡AND-­‑OR ¡construc7on. ¡

Transforms ¡a ¡(.2,.8,.8,.2)-­‑sensi7ve ¡family ¡into ¡a ¡ ¡

(.2,.8,.9999996,.0008715)-­‑sensi7ve ¡family! ¡

How ¡many ¡hash ¡func7ons ¡are ¡used? ¡

25 ¡

slide-26
SLIDE 26

Other ¡examples ¡of ¡LS ¡families ¡

So ¡far: ¡Jaccard ¡distance ¡has ¡a ¡LS ¡hash ¡family ¡ Several ¡other ¡distance ¡func7ons ¡do ¡too ¡

Cosine ¡distance ¡ Euclidean ¡distance ¡

26 ¡

slide-27
SLIDE 27

LSH ¡for ¡Cosine ¡Distance ¡

27 ¡

slide-28
SLIDE 28

LSH ¡for ¡Euclidean ¡distance ¡

Key ¡idea: ¡Map ¡points ¡to ¡random ¡line ¡ Here, ¡let’s ¡consider ¡2 ¡dimensions ¡(but ¡generalizes) ¡

28 ¡

slide-29
SLIDE 29

LSH ¡for ¡Euclidean ¡distance ¡

29 ¡

Bucket width a Randomly chosen line Points at distance d If d < a, then the chance the points are in the same bucket is

slide-30
SLIDE 30

LSH ¡for ¡Euclidean ¡distance ¡

30 ¡

Bucket width a Randomly chosen line Points at distance d θ d cos θ If d >> a, θ must be close to 90o for there to be any chance points go to the same bucket.

slide-31
SLIDE 31

LSH ¡for ¡Euclidean ¡distance ¡

If ¡distance ¡ ¡d ¡< ¡a/2, ¡P(same ¡bucket) ¡≥ ¡1-­‑ ¡d/a ¡= ¡1/2 ¡ If ¡distance ¡d ¡> ¡2a, ¡then ¡they ¡can ¡end ¡up ¡in ¡the ¡same ¡

bucket ¡only ¡if ¡d ¡cos ¡θ ¡≤ ¡a ¡ ¡

cos ¡θ ¡≤ ¡½ ¡ ¡ 60 ¡< ¡θ ¡< ¡90 ¡ This ¡event ¡has ¡probability ¡at ¡most ¡1/3. ¡

Yields ¡a ¡(a/2, ¡2a, ¡1/2, ¡1/3)-­‑sensi7ve ¡family ¡of ¡hash ¡

func7ons ¡for ¡any ¡a. ¡

Can ¡boost ¡using ¡AND-­‑OR ¡construc7ons ¡

31 ¡

slide-32
SLIDE 32

LSH ¡in ¡MapReduce? ¡

LSH ¡is ¡well ¡suited ¡for ¡MapReduce ¡style ¡computa7on! ¡ You’ll ¡find ¡out ¡how ¡in ¡the ¡homework ¡J ¡

32 ¡

slide-33
SLIDE 33

LSH ¡for ¡nearest ¡neighbor ¡search ¡

So ¡far ¡we ¡discussed ¡the ¡problem ¡of ¡finding ¡near ¡

  • duplicates. ¡

How ¡do ¡we ¡implement ¡nearest ¡neighbor ¡search? ¡

33 ¡

slide-34
SLIDE 34

Approximate ¡near-­‑neighbor ¡search ¡

Consider ¡slightly ¡different ¡problem: ¡approximate ¡near ¡

neighbor ¡search ¡

Want ¡to ¡find ¡any ¡point ¡in ¡data ¡set ¡that ¡has ¡distance ¡at ¡most ¡

r ¡from ¡query ¡

Don’t ¡want ¡to ¡return ¡points ¡of ¡distance ¡more ¡than ¡(1+ε) ¡r ¡

Pick ¡(r, ¡(1+ε) ¡r, ¡p,q)-­‑sensi5ve ¡hash ¡family ¡

Preprocessing: ¡Hash ¡data ¡set ¡as ¡in ¡duplicate ¡detec7on

¡

Query: ¡Hash ¡query ¡in ¡the ¡same ¡way ¡ Retrieve ¡all ¡candidate ¡pairs ¡(perhaps ¡pick ¡closest) ¡

¡

34 ¡

slide-35
SLIDE 35

Approximate ¡nearest ¡neighbor ¡search ¡

Can ¡we ¡use ¡approximate ¡near-­‑neighbor ¡search ¡for ¡

(approximate) ¡nearest-­‑neighbor ¡search? ¡

35 ¡

slide-36
SLIDE 36

36 ¡

slide-37
SLIDE 37

Course ¡organiza7on ¡

Retrieval ¡

Given ¡a ¡query, ¡find ¡“most ¡similar” ¡item ¡in ¡a ¡large ¡data ¡set ¡ Applica5ons: ¡GoogleGoggles, ¡Shazam, ¡… ¡

Supervised ¡learning ¡(Classifica7on, ¡Regression) ¡

Learn ¡a ¡concept ¡(func7on ¡mapping ¡queries ¡to ¡labels) ¡ Applica5ons: ¡Spam ¡filtering, ¡predic7ng ¡price ¡changes, ¡… ¡

Unsupervised ¡learning ¡(Clustering, ¡dimension ¡reduc7on)

¡

Iden7fy ¡clusters, ¡“common ¡paverns”; ¡anomaly ¡detec7on ¡ Applica5ons: ¡Recommender ¡systems, ¡fraud ¡detec7on, ¡… ¡

Learning ¡with ¡limited ¡feedback ¡

Learn ¡to ¡op7mize ¡a ¡func7on ¡that’s ¡expensive ¡to ¡evaluate ¡ Applica5ons: ¡Online ¡adver7sing, ¡opt. ¡UI, ¡learning ¡rankings, ¡… ¡

37 ¡

slide-38
SLIDE 38

Classifica7on ¡(intui7vely) ¡

Want ¡to ¡assign ¡data ¡points ¡

Documents ¡ Queries ¡ Images ¡ Audio ¡ … ¡

¡ ¡ ¡ ¡a ¡label ¡(spam/not-­‑spam; ¡topic ¡such ¡as ¡sports, ¡poli7cs, ¡ ¡ ¡ ¡ ¡ ¡entertainment, ¡etc.) ¡

Goal: ¡ ¡

extract ¡rules ¡(hypotheses) ¡based ¡on ¡training ¡examples. ¡ Hope ¡that ¡those ¡rules ¡generalize ¡to ¡previously ¡unseen ¡data ¡

38 ¡

slide-39
SLIDE 39

39 ¡

Document ¡classifica7on ¡

Input: ¡Labeled ¡data ¡set ¡(e.g., ¡rep. ¡bag-­‑of-­‑words) ¡with ¡

posi7ve ¡(+) ¡and ¡nega7ve ¡(-­‑) ¡examples ¡

Output: ¡Decision ¡rule ¡(hypothesis) ¡

+ – + + + + + – – – –

– –

Spam ¡ Ham ¡

+ –

slide-40
SLIDE 40

Linear ¡classifiers ¡

Data ¡set ¡

40 ¡

+ – + + + + + – – – –

– – + –

(x1, y1), . . . , (xn, yn)

slide-41
SLIDE 41

Which ¡linear ¡classifier ¡is ¡the ¡best ¡one? ¡

Data ¡set ¡ Linear ¡classifier: ¡

41 ¡

+ – + + + + + – – – –

– – + –

(x1, y1), . . . , (xn, yn) sign(wT x + b)

slide-42
SLIDE 42

Large ¡margin ¡classifica7on ¡

Margin ¡of ¡

confidence: ¡

Want ¡to ¡maximize ¡

confidence ¡in ¡our ¡ predic7on! ¡

Turns ¡out ¡to ¡be ¡the ¡“right” ¡thing ¡to ¡do ¡

Larger ¡margin ¡è ¡Bever ¡generaliza7on ¡

42 ¡

+ – + + + + + – – – –

– – + –

slide-43
SLIDE 43

Nonuniqueness ¡

43 ¡

+ – + + + + + – – – –

– – + –

max

w,b,γ γ

s.t.(wT xi + b)yi ≥ γ

So ¡far, ¡our ¡no7on ¡of ¡confidence ¡is ¡not ¡yet ¡well ¡defined! ¡

slide-44
SLIDE 44

Review: ¡Projec7on ¡on ¡a ¡plane ¡

44 ¡

.

slide-45
SLIDE 45

Canonical ¡hyperplanes ¡

45 ¡

+ – + + + + + – – – –

– – + –

wT x + b = 1 wT x + b = −1 wT x + b = 0

slide-46
SLIDE 46

Maximizing ¡the ¡normalized ¡margin ¡

46 ¡

+ – + + + + + – – – –

– – + –

wT x + b = 1 wT x + b = −1 wT x + b = 0

max

w,b,γ γ

s.t.(wT xi + b)yi ≥ γ

slide-47
SLIDE 47

Acknowledgments ¡

Several ¡slides ¡adapted ¡from ¡the ¡material ¡

accompanying ¡the ¡textbook ¡(Anand ¡Rajaraman, ¡ Stanford) ¡

47 ¡