19
Instance Based Learning Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber Instance-Based Learning (IBL): k-Nearest Neighbor e Case-Based Reasoning Lecture 7 Lecture 7

Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

  • Upload
    gyala

  • View
    21

  • Download
    0

Embed Size (px)

DESCRIPTION

Lecture 7. Instance-Based Learning (IBL): k -Nearest Neighbor e Case-Based Reasoning. Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber. I nstance- B ased L earning (IBL). Idea Conserviamo (più o meno) tutte le istanze < x , c ( x )> - PowerPoint PPT Presentation

Citation preview

Page 1: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Mercoledì, 17 novembre 2004

Giuseppe Manco

Readings:

Chapter 8, Mitchell

Chapter 7, Han & Kamber

Instance-Based Learning (IBL):k-Nearest Neighbor e Case-Based Reasoning

Lecture 7Lecture 7

Page 2: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

IInstance-nstance-BBased ased LLearning (IBL)earning (IBL)

• Idea

– Conserviamo (più o meno) tutte le istanze <x, c(x)>

– Classificazione: Data una istanza xq

– Restituiiamo: il concetto dell’istanza più prossima nel database di prototipi

– Giustificazione

• L’istanza più prossima a xq tende ad avere lo stesso concetto di f(xq)

• Non vale quando i dati sono pochi

• Nearest Neighbor

– Si trovi l’esempio xn nel training set che sia più vicino alla query xq

– Si effettui la stima

• k-Nearest Neighbor

– f nominale: votazione tra I k vicini “più vicini” a xq

– f numerica:

nq xfxf ˆ

k

xfxf

k

i iq

Page 3: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

• Proprietà ideali

– Istanze in Rn

– Meno di 20 attributi per instanza

– Training set molto grande

• Vantaggi

– Training veloce

– Apprendimento di funzioni complesse

– Non c’à perdita di informazione

• Svantaggi

– Lento a tempo di classificazione

– Attributi irrelevanti influenzano il tutto

Quando usare Nearest NeighborQuando usare Nearest Neighbor

Page 4: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Triangolazione di Delaunay

Diagrammi di Voronoi(Nearest Neighbor)

Diagrammi di VoronoiDiagrammi di Voronoi

Training Data:Istanze etichettate

+

-

-

--

-

+

+

+

+

-

Queryxq

?

Page 5: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

kk-NN Pesato-NN Pesato

• Idea

– Utilizziamo tutti i dati, associamo un peso ai vicini

• Funzione di peso

– I pesi sono proporzionali alla distanza:

– d(xq, xi) è la distanza euclidea

k

i i

k

i iiq

w

xfwxf

1

21

iq

ix ,xd

w

Page 6: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Case-Based Reasoning (CBR)Case-Based Reasoning (CBR)

• IBL applicato a dati non numerici

– Necessità di una nozione differente di “distanza”

– Idea: utilizziamo misure di similarità simbolica (sintattica)

Page 7: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

EsempioEsempio

Istanza X1 X2 X3

I1 0 0 0

I2 1 0 0

I3 2 0 0

I4 2.5 2 0

I5 3 0 0

I6 1 2 1

I7 1.5 0 1

I8 2 2 1

I9 3 2 1

I10 4 2 1

),(),(),(

..

.

.

..

.),(),(

),(...),(),(

1010210110

2212

1012111

IIdIIdIId

IIdIId

IIdIIdIId

Page 8: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Similarità e dissimilarità tra oggettiSimilarità e dissimilarità tra oggetti

• La distanza è utilizzata per misurare la similarità (o dissimilarità) tra

due istanze

• Some popular ones include: Minkowski distance:

– Dove xi = (xi1, xi2, …, xip) e xj = (xj1, xj2, …, xjp) sono due oggetti p-

dimensionali, e q è un numero primo

• se q = 1, d è la distanza Manhattan

qq

pp

qq

jx

ix

jx

ix

jx

ixjid )||...|||(|),(

2211xx

||...||||),(2211 pp jxixjxixjxixjid xx

Page 9: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Similarità e dissimilarità tra oggetti [2]Similarità e dissimilarità tra oggetti [2]

• se q = 2, d è la distanza euclidea:

– Proprietà

• Varianti– Distanza pesata

– Distanza Mahalanobis

)||...||2

|(|1

),( 22

22

2

11 pp jx

ixpw

jx

ixw

jx

ixwjid xx

)||...|||(|),( 22

22

2

11 pp jx

ix

jx

ix

jx

ixjid xx

jT

ijid xΣxxx 1),(

),(),(),(

),(),(

0),(

0),(

jkkiji

ijji

ii

ji

ddd

dd

d

d

xxxxxx

xxxx

xx

xx

Page 10: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

EsempioEsempio

04,54,54,54,54,54,54,54,54,5

4,503,73,73,73,73,73,73,73,7

4,53,703333333

4,53,7301,81,81,81,81,81,8

4,53,731,802,42,42,42,42,4

4,53,731,82,403333

4,53,731,82,4303,23,23,2

4,53,731,82,433,2022

4,53,731,82,433,2201

4,53,731,82,433,2210

00,93,67,658,14,57,655,48,112,6

0,900,95,853,65,45,854,55,48,1

3,60,905,850,98,15,855,44,55,4

7,655,855,8507,657,65185,855,857,65

8,13,60,97,65012,67,658,15,44,5

4,55,48,17,6512,607,650,93,68,1

7,655,855,85187,657,6505,855,857,65

5,44,55,45,858,10,95,8500,93,6

8,15,44,55,855,43,65,850,900,9

12,68,15,47,654,58,17,653,60,90

0777777777

7066666666

7605555555

76502,52,52,52,52,52,5

7652,5044444

7652,5403333

7652,54304,54,54,5

7652,5434,5022

7652,5434,5201

7652,5434,5210

Euclidea

manhattan

mahalanobis

Page 11: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

• Similarità del coseno

• Similarità di Jaccard– Su dati reali

• Studio dell’effetto delle varie misure di similarità nei clusters

Page 12: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Attributi binariAttributi binari

• Distanza di Hamming

– Distanza Manhattan quando i valori possibili sono 0 o 1

• In pratica, conta il numero di mismatches

||...||||),(2211 pp jxixjxixjxixjid xx

Page 13: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Attributi binariAttributi binari

• Utilizzando la tabella di contingenza

• Coefficiente di matching (invariante, se le variabili sono simmetriche):

• Coefficiente di Jaccard (noninvariante se le variabili sono asimmetriche):

dcbacb jid

),(

cbacb jid

),(

pdbca

dcdc

baba

totale

totale

0

1

01

Oggetto i

Oggetto j

Page 14: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Dissimilarità tra attributi binariDissimilarità tra attributi binari

• Esempio

– gender è simmetrico– Tutti gli altri sono asimmetrici– Poniamo Y e P uguale a 1, e N a 0

Name Gender Fever Cough Test-1 Test-2 Test-3 Test-4

Jack M Y N P N N NMary F Y N P N P NJim M Y P N N N N

75.0211

21),(

67.0111

11),(

33.0102

10),(

maryjimd

jimjackd

maryjackd

Page 15: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Indici di similarità demograficaIndici di similarità demografica

• Proporzionale al numero di “uni” comuni (1-1)• Inversamente proporzionale agli 0-1 e ai 1-0• Non affetta da 0-0• Indice di Condorcet =

– a / (a + 1/2(b + c))• Indice di Dice =

– a / (a + 1/4(b + c))• Dice meno efficace di Condorcet

– Appropriato su oggetti estremamente differenti

Page 16: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Variabili NominaliVariabili Nominali

• Generalizzazione del meccanismo di variabili binarie

• Metodo 1: Matching semplice

– m: # di matches, p: # di attributi nominali

• metodo 2: binarizzazione

pmpjid ),(

Page 17: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Esercizio: PlayTennisEsercizio: PlayTennis

Day Outlook Temperature Humidity Wind PlayTennis?1 Sunny Hot High Light No2 Sunny Hot High Strong No3 Overcast Hot High Light Yes4 Rain Mild High Light Yes5 Rain Cool Normal Light Yes6 Rain Cool Normal Strong No7 Overcast Cool Normal Strong Yes8 Sunny Mild High Light No9 Sunny Cool Normal Light Yes10 Rain Mild Normal Light Yes11 Sunny Mild Normal Strong Yes12 Overcast Mild High Strong Yes13 Overcast Hot Normal Light Yes14 Rain Mild High Strong No

Page 18: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Playtennis [2]Playtennis [2]

• d(I,d1) = 2/4 = 0.5

• d(I,d2) = 1/4 = 0.25

• d(I,d3) = 3/4 = 0.75

• d(I,d4) = 3/4 = 0.75

• d(I,d5) = 3/4 = 0.75

• d(I,d6) = 2/4 = 0.5

• d(I,d7) = 2/4 = 0.75

• d(I,d8) = 2/4 = 0.5

• d(I,d9) = 2/4 = 0.5

• d(I,d10) = 3/4 = 0.75

• d(I,d11) = 2/4 = 0.5

• d(I,d12) = 2/4 = 0.5

• d(I,d13) = 4/4 = 1

• d(I,d14) = 2/4 = 0.5

Day Outlook Temperature Humidity Wind PlayTennis?1 Sunny Hot High Light No2 Sunny Hot High Strong No3 Overcast Hot High Light Yes4 Rain Mild High Light Yes5 Rain Cool Normal Light Yes6 Rain Cool Normal Strong No7 Overcast Cool Normal Strong Yes8 Sunny Mild High Light No9 Sunny Cool Normal Light Yes10 Rain Mild Normal Light Yes11 Sunny Mild Normal Strong Yes12 Overcast Mild High Strong Yes13 Overcast Hot Normal Light Yes14 Rain Mild High Strong No

Page 19: Mercoledì, 17 novembre 2004 Giuseppe Manco Readings: Chapter 8, Mitchell Chapter 7, Han & Kamber

Instance Based Learning

Lazy e Eager LearningLazy e Eager Learning

• Lazy Learning

– Nessuna generalizzazione: aspettiamo la query

• k-nearest neighbor (k-NN)

• Case-based reasoning (CBR)

• Eager Learning

– generalizzazione

• ID3, backpropagation, simple (Naïve) Bayes, etc.

• Qual’è la differenza?

– Eager crea un’approssimazione globale

– Lazy può creare molte approssimazioni locali