Probability and Statistics for Computer Science (II) - - PowerPoint PPT Presentation

probability and statistics
SMART_READER_LITE
LIVE PREVIEW

Probability and Statistics for Computer Science (II) - - PowerPoint PPT Presentation

Probability and Statistics for Computer Science (II) Correla)on is not Causa)on but Correla)on is so beau)ful! Credit: wikipedia Hongye Liu,


slide-1
SLIDE 1

ì ¡

Probability ¡and ¡Statistics ¡ for ¡Computer ¡Science ¡(II) ¡

“Correla)on ¡is ¡not ¡Causa)on” ¡ but ¡Correla)on ¡is ¡so ¡beau)ful! ¡

Hongye ¡Liu, ¡Teaching ¡Assistant ¡Prof, ¡CS361, ¡UIUC, ¡8.29.2019 ¡ Credit: ¡wikipedia ¡

slide-2
SLIDE 2

Last ¡time ¡

✺ Variance ¡ ✺ Standardizing ¡data ¡ ✺ Median, ¡interquar)le ¡

range, ¡box ¡plots ¡and ¡

  • utliers ¡

✺ Visualizing ¡& ¡

Summarizing ¡ rela)onships ¡

✺ Heatmap ¡ ✺ 3D ¡bar ¡ ✺ Time ¡series ¡plots ¡ ✺ ScaUer ¡plots ¡ ✺ Correla)on ¡

coefficient ¡

slide-3
SLIDE 3

One ¡correction ¡

slide-4
SLIDE 4

Q: ¡Estimate ¡the ¡range ¡of ¡data ¡in ¡ standard ¡coordinates ¡ ¡

¡

✺ Es)mate ¡as ¡close ¡as ¡possible, ¡99% ¡data ¡

is ¡within: ¡ ¡

¡A. ¡[-­‑10, ¡10] ¡ ¡ ¡ ¡B. ¡[-­‑100, ¡100] ¡ ¡C. ¡[-­‑1, ¡1] ¡ ¡D. ¡[-­‑4, ¡4] ¡ ¡E. ¡others ¡

  • xi = xi − mean({xi})

std({xi)}

90 ¡

slide-5
SLIDE 5

Homework ¡(I) ¡

✺ Due ¡on ¡Sept. ¡9 ¡ ✺ There ¡is ¡one ¡op)onal ¡problem ¡with ¡

extra ¡5 ¡points. ¡(Won’t ¡be ¡in ¡exams) ¡

✺ Gradescope ¡has ¡been ¡set ¡up. ¡Entry ¡

Code:M3DWYE ¡ ¡

✺ Online ¡latex ¡editor ¡for ¡wri)ng ¡

formulas ¡

slide-6
SLIDE 6

Office ¡hours ¡& ¡Attendance ¡

✺ Office ¡hours ¡of ¡the ¡staff ¡are ¡updated ¡ ✺ We ¡can ¡adjust ¡the ¡schedule ¡if ¡there ¡is ¡

a ¡need ¡

✺ AUendance ¡will ¡be ¡tracked ¡from ¡

today ¡

slide-7
SLIDE 7

Today ¡

✺ Visualizing ¡& ¡Summarizing ¡

rela)onships ¡

✺ Correla)on ¡coefficient ¡ ¡ ✺ Predic)on ¡with ¡correla)on ¡

coefficient ¡

slide-8
SLIDE 8

It’s ¡about ¡Relationship ¡between ¡ data ¡features ¡

✺ Example: ¡does ¡the ¡Height ¡of ¡people ¡relate ¡to ¡

people’s ¡weight? ¡ ¡

✺ x ¡: ¡ ¡HIGHT, ¡ ¡y: ¡WEIGHT ¡

slide-9
SLIDE 9

Correlation ¡Coefficient ¡

✺ Given ¡a ¡data ¡set ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡consis)ng ¡of ¡

items ¡ ¡

✺ Standardize ¡the ¡coordinates ¡of ¡each ¡feature: ¡ ✺ Define ¡the ¡correla)on ¡coefficient ¡as: ¡

corr({(xi, yi)}) = 1 N

N

  • i=1
  • xi

yi

{(xi, yi)}

(x1, y1) ... (xN, yN),

  • xi = xi − mean({xi})

std({xi})

  • yi = yi − mean({yi})

std({yi})

slide-10
SLIDE 10

Correlation ¡Coefficient ¡

¡

corr({(xi, yi)}) = 1 N

N

  • i=1
  • xi

yi

  • xi = xi − mean({xi})

std({xi})

  • yi = yi − mean({yi})

std({yi})

slide-11
SLIDE 11

Q: ¡Correlation ¡Coefficient ¡

✺ Which ¡of ¡the ¡following ¡describe(s) ¡

correla)on ¡coefficient ¡correctly? ¡ ¡A. ¡It’s ¡unitless ¡ ¡ ¡ ¡ ¡ ¡

¡B. ¡It’s ¡defined ¡in ¡standard ¡coordinates ¡ ¡ ¡ ¡ ¡ ¡C. ¡Both ¡A ¡& ¡B ¡

corr({(xi, yi)}) = 1 N

N

  • i=1
  • xi

yi

slide-12
SLIDE 12

A ¡visualization ¡of ¡correlation ¡ coefficient ¡

hUps://rpsychologist.com/d3/correla)on/ ¡ In ¡a ¡data ¡set ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡consis)ng ¡of ¡items ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡shows ¡posi)ve ¡correla)on ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡shows ¡nega)ve ¡correla)on ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡shows ¡no ¡correla)on ¡

{(xi, yi)} (x1, y1) ... (xN, yN),

corr({(xi, yi)}) > 0 corr({(xi, yi)}) < 0 corr({(xi, yi)}) = 0

slide-13
SLIDE 13

Correlation ¡seen ¡from ¡scatter ¡plots ¡

Posi)ve ¡ ¡ correla)on ¡ ¡ Nega)ve ¡ ¡ correla)on ¡ Zero ¡ ¡ Correla)on ¡ ¡

Credit: ¡ Prof.Forsyth ¡

slide-14
SLIDE 14

The ¡Properties ¡of ¡ ¡Correlation ¡ Coefficient ¡

✺ The ¡correla)on ¡coefficient ¡is ¡symmetric ¡ ¡ ✺ Transla)ng ¡the ¡data ¡does ¡NOT ¡change ¡the ¡

correla)on ¡coefficient ¡

corr({(xi, yi)}) = corr({(yi, xi)})

slide-15
SLIDE 15

The ¡Properties ¡of ¡ ¡Correlation ¡ Coefficient ¡

✺ Scaling ¡the ¡data ¡may ¡change ¡the ¡sign ¡of ¡

the ¡correla)on ¡coefficient ¡

corr({(a xi + b, c yi + d)}) = sign(a c)corr({(xi, yi)})

slide-16
SLIDE 16

The ¡Properties ¡of ¡ ¡Correlation ¡ Coefficient ¡

✺ The ¡correla)on ¡coefficient ¡is ¡bounded ¡

within ¡[-­‑1, ¡1] ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡and ¡only ¡if ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡and ¡only ¡if ¡

corr({(xi, yi)}) = 1 corr({(xi, yi)}) = −1

  • xi =

yi

  • xi = −

yi

slide-17
SLIDE 17

Concept ¡of ¡ ¡Correlation ¡Coefficient’s ¡ bound ¡

✺ The ¡correla)on ¡coefficient ¡can ¡be ¡

wriUen ¡as ¡

✺ It’s ¡the ¡inner ¡product ¡of ¡two ¡vectors ¡

¡ ¡ ¡ ¡ ¡ ¡and ¡ ¡

corr({(xi, yi)}) =

N

  • i=1
  • xi

√ N

  • yi

√ N corr({(xi, yi)}) = 1 N

N

  • i=1
  • xi

yi

  • x1

√ N ,

...

  • xN

√ N

  • y1

√ N ,

...

  • yN

√ N

slide-18
SLIDE 18

Inner ¡product ¡

✺ Inner ¡product’s ¡geometric ¡meaning: ¡ ✺ Lengths ¡of ¡both ¡vectors ¡

are ¡1 ¡

θ ¡ ν2 ¡ ν1 ¡

|ν1| |ν2| cos(θ)

ν1= ¡ ν2= ¡

  • x1

√ N ,

...

  • xN

√ N

  • y1

√ N ,

...

  • yN

√ N

slide-19
SLIDE 19

Bound ¡of ¡correlation ¡coefficient ¡

θ ¡ ν2 ¡ ν1 ¡

|corr({(xi, yi)})| = |cos(θ)| ≤ 1

ν1= ¡ ν2= ¡

  • x1

√ N ,

...

  • xN

√ N

  • y1

√ N ,

...

  • yN

√ N

slide-20
SLIDE 20

The ¡Properties ¡of ¡ ¡Correlation ¡ Coefficient ¡

✺ Symmetric ¡ ✺ Transla)ng ¡invariant ¡ ¡ ✺ Scaling ¡only ¡may ¡change ¡sign ¡ ✺ bounded ¡within ¡[-­‑1, ¡1] ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

slide-21
SLIDE 21

Using ¡correlation ¡to ¡predict ¡

¡

✺ Cau*on! ¡Correla)on ¡is ¡NOT ¡Causa)on ¡

Credit: ¡Tyler ¡ ¡Vigen ¡

slide-22
SLIDE 22

How ¡do ¡we ¡go ¡about ¡the ¡prediction? ¡

✺ Removed ¡of ¡outliers ¡& ¡standardized ¡

slide-23
SLIDE 23

Using ¡correlation ¡to ¡predict ¡

¡

✺ ¡Given ¡a ¡correlated ¡data ¡set ¡

¡we ¡can ¡predict ¡a ¡value ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡that ¡goes ¡with ¡ ¡a ¡value ¡ ¡ ¡

{(xi, yi)}

y0

p

x0

¡

✺ ¡In ¡standard ¡coordinates ¡ ¡

¡we ¡can ¡predict ¡a ¡value ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡that ¡goes ¡with ¡ ¡a ¡value ¡ ¡ ¡

{( xi, yi)}

  • y0

p

  • x0
slide-24
SLIDE 24

Q: ¡

¡

✺ ¡Which ¡coordinates ¡will ¡you ¡use ¡for ¡the ¡

predictor ¡using ¡correla)on? ¡

¡

¡A. ¡ ¡Standard ¡coordinates ¡ ¡ ¡B. ¡ ¡Original ¡coordinates ¡ ¡ ¡

slide-25
SLIDE 25

Linear ¡predictor ¡and ¡its ¡error ¡

¡

✺ We ¡will ¡assume ¡that ¡our ¡predictor ¡is ¡linear ¡ ✺ We ¡denote ¡the ¡predic)on ¡at ¡each ¡ ¡ ¡ ¡ ¡ ¡ ¡in ¡the ¡data ¡

set ¡as ¡ ¡

✺ The ¡error ¡in ¡the ¡predic)on ¡is ¡denoted ¡

¡

ui

  • xi
  • yi

p

  • y p = a

x + b

  • yi

p = a

xi + b

ui = yi − yi

p =

yi − a xi − b

slide-26
SLIDE 26

Require ¡the ¡mean ¡of ¡error ¡to ¡be ¡zero ¡

We ¡would ¡try ¡to ¡make ¡the ¡mean ¡of ¡error ¡equal ¡to ¡ zero ¡so ¡that ¡it ¡is ¡also ¡centered ¡around ¡0 ¡as ¡ ¡ the ¡standardized ¡data: ¡

mean({ui}) = 0 ⇒ mean({ yi − a xi − b}) = 0 ⇒ mean({ yi}) − a mean({ xi}) − b = 0 ⇒ −b = 0 ⇒ b = 0 ⇒ y p = a x

0 ¡ 0 ¡

slide-27
SLIDE 27

Require ¡the ¡variance ¡of ¡error ¡is ¡ minimal ¡

var({ui}) = mean({(ui − mean({ui}))2})

0 ¡

= mean({u2

i })

= mean({( yi − yi

p)2})

= mean({( yi − a xi)2}) = mean({( yi

2 − 2a

xi yi + a2 xi

2)})

= var({ yi}) − 2a corr({ xi yi}) + a2var({ xi})

r

1 ¡ 1 ¡

slide-28
SLIDE 28

Require ¡the ¡variance ¡of ¡error ¡is ¡ minimal ¡

assume corr({ xi yi}) = r Since var({ yi}) = 1; var({ xi}) = 1

var({ui}) = 1 − 2ar + a2

Con)nue ¡here: ¡ ¡ Differen)ate ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡with ¡respect ¡to ¡

var({ui})

a

d(var({ui})) da = −2r + 2a = 0 ⇒ a = r

slide-29
SLIDE 29

Here ¡is ¡the ¡linear ¡predictor! ¡

  • y p = r

x

Correla)on ¡coefficient ¡

slide-30
SLIDE 30

Prediction ¡Formula ¡

¡

✺ In ¡standard ¡coordinates ¡

¡

✺ In ¡original ¡coordinates ¡

r = corr({(xi, yi)})

  • y0

p − mean({yi})

std({yi}) = r x0 − mean({xi}) std({xi})

  • y0

p = r

x0

where ¡

slide-31
SLIDE 31

Root-­‑mean-­‑square ¡(RMS) ¡prediction ¡ error ¡

Given var({ui}) = 1 − 2ar + a2 & a = r var({ui}) = 1 − r2

RMS error =

  • mean({u2

i })

¡

✺ ¡ ¡

¡

✺ ¡ ¡

= √ 1 − r2

=

  • var({ui})
slide-32
SLIDE 32

See ¡the ¡error ¡through ¡simulation ¡

hUps://rpsychologist.com/d3/correla)on/ ¡

slide-33
SLIDE 33

Example: ¡Body ¡Fat ¡data ¡

r ¡= ¡0.513 ¡

slide-34
SLIDE 34

Example: ¡remove ¡2 ¡more ¡outliers ¡

r ¡= ¡0.556 ¡

slide-35
SLIDE 35

Assignments ¡

✺ Reading ¡Chapter ¡2 ¡of ¡the ¡textbook ¡ ✺ Next ¡)me: ¡Probability ¡a ¡first ¡look ¡

¡

slide-36
SLIDE 36

Additional ¡References ¡

✺ Peter ¡Dalgaard ¡"Introductory ¡Sta)s)cs" ¡

with ¡R ¡

✺ Charles ¡M. ¡Grinstead ¡and ¡J. ¡Laurie ¡Snell ¡

"Introduc)on ¡to ¡Probability” ¡ ¡

✺ Morris ¡H. ¡Degroot ¡and ¡Mark ¡J. ¡Schervish ¡

"Probability ¡and ¡Sta)s)cs” ¡

slide-37
SLIDE 37

Acknowledgement ¡

Thank You!