29
Nearest Neighbor An Explanation of Nearest Neighbor and how to use it to get to know your data in Matlab

Won't You be my Nearest Neighbor?

Embed Size (px)

Citation preview

Page 1: Won't You be my Nearest Neighbor?

Nearest Neighbor

An Explanation of Nearest Neighbor and how to use it to get to

know your data in Matlab

Page 2: Won't You be my Nearest Neighbor?

Match Making for Soda Lovers

Page 3: Won't You be my Nearest Neighbor?
Page 4: Won't You be my Nearest Neighbor?

Sw

eetness

Page 5: Won't You be my Nearest Neighbor?

Sw

eetness

Carbonation

Page 6: Won't You be my Nearest Neighbor?

Sw

eetness

Carbonation

Price

Page 7: Won't You be my Nearest Neighbor?

Sw

eetness

Carbonation

Price

Acidity

Page 8: Won't You be my Nearest Neighbor?

Sw

eetness

Carbonation

Price

Acidity

Caffeination

Page 9: Won't You be my Nearest Neighbor?

Sw

eetness

Carbonation

Price

Acidity

Caffeination

Etc.

Page 10: Won't You be my Nearest Neighbor?

Sw

eetness

Carbonation

Price

Acidity

Caffeination

Etc.

Etc.

Page 11: Won't You be my Nearest Neighbor?

Sw

eetness

Carbonation

Price

Acidity

Caffeination

Etc.

Etc.

Etc.

Page 12: Won't You be my Nearest Neighbor?

Sweetness

Carbonation

Price

Soda ID Sweetness Carbonation Price

Soda 1 3.5 4.3 $1.00

Soda 2 5.1 4.1 $1.50

Soda 3 4.2 2.2 $2.00

Soda 4 3.1 4.2 $0.75

Soda 5 6 3.0 $0.50

Page 13: Won't You be my Nearest Neighbor?

Sweetness

Carbonation

Price

xlsread(filename)csvread(filename)

Sweetness Carbonation Price

3.5 4.3 $1.00

5.1 4.1 $1.50

4.2 2.2 $2.00

3.1 4.2 $0.75

6 3.0 $0.50

Soda Brand

Soda 1

Soda 2

Soda 3

Soda 4

Soda 5

[SODAS, BRANDS] = xlsread(filename)

Page 14: Won't You be my Nearest Neighbor?
Page 15: Won't You be my Nearest Neighbor?
Page 16: Won't You be my Nearest Neighbor?
Page 17: Won't You be my Nearest Neighbor?
Page 18: Won't You be my Nearest Neighbor?

*

Page 19: Won't You be my Nearest Neighbor?

***

**

*

*

**

***

Page 20: Won't You be my Nearest Neighbor?

***

**

*

*

**

***

Page 21: Won't You be my Nearest Neighbor?

***

**

*

*

**

***

Page 22: Won't You be my Nearest Neighbor?

***

**

*

*

**

***

Page 23: Won't You be my Nearest Neighbor?

The Basic Math

Differencein Sweetness

Differencein Carbonation

Differencein Price

Sweetness

Carbona

tion

a

b

A^2 + b^2 = c^3

Distance:(in lots of dimensions)

Page 24: Won't You be my Nearest Neighbor?

MatlabdsearchnN-Dimensional nearest point search

Syntaxk = dsearchn(SODAS,IDEALS)

rangesearchFind all neighbors specified distance using KDTreeSearcher object

Syntax[idx,D]= rangesearch(SODATREE,IDEALS,r)

Page 25: Won't You be my Nearest Neighbor?

MatlabdsearchnN-Dimensional nearest point search

Syntaxk = dsearchn(SODAS,IDEALS)

knnsearchFind k-nearest neighbors using data

Syntax[IDX,D] = knnsearch(SODATREE,IDEALS,r)

For single nearestpoint

For More Neighbors(requires a tree)

Page 26: Won't You be my Nearest Neighbor?

Easy One Match SearchdsearchnN-Dimensional nearest point search

SyntaxI = dsearchn(SODAS,IDEALS)

Page 27: Won't You be my Nearest Neighbor?

Harder Multi Match SearchBuilding a Tree

Sweetness Carbonation Price

3.5 4.3 $1.00

5.1 4.1 $1.50

4.2 2.2 $2.00

3.1 4.2 $0.75

6 3.0 $0.50

SODATREE = kdtreesearcher(SODAS,'distance')

All the Sodas

Page 28: Won't You be my Nearest Neighbor?

Sweetness Carbonation Price

3.5 4.3 $1.00

5.1 4.1 $1.50

4.2 2.2 $2.00

rangesearchFind all neighbors specified distance using KDTreeSearcher object

Syntax[I,D]= rangesearch(SODATREE,IDEALS,r)

**r

Harder Multi Match SearchGetting neighbors

Ideal Sodas

Page 29: Won't You be my Nearest Neighbor?