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 Last ¡time ¡
✺ Variance ¡ ✺ Standardizing ¡data ¡ ✺ Median, ¡interquar)le ¡
range, ¡box ¡plots ¡and ¡
✺ Visualizing ¡& ¡
Summarizing ¡ rela)onships ¡
✺ Heatmap ¡ ✺ 3D ¡bar ¡ ✺ Time ¡series ¡plots ¡ ✺ ScaUer ¡plots ¡ ✺ Correla)on ¡
coefficient ¡
SLIDE 3
One ¡correction ¡
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 ¡
std({xi)}
90 ¡
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
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
Today ¡
✺ Visualizing ¡& ¡Summarizing ¡
rela)onships ¡
✺ Correla)on ¡coefficient ¡ ¡ ✺ Predic)on ¡with ¡correla)on ¡
coefficient ¡
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 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
yi
{(xi, yi)}
(x1, y1) ... (xN, yN),
std({xi})
std({yi})
SLIDE 10 Correlation ¡Coefficient ¡
¡
corr({(xi, yi)}) = 1 N
N
yi
std({xi})
std({yi})
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
yi
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 Correlation ¡seen ¡from ¡scatter ¡plots ¡
Posi)ve ¡ ¡ correla)on ¡ ¡ Nega)ve ¡ ¡ correla)on ¡ Zero ¡ ¡ Correla)on ¡ ¡
Credit: ¡ Prof.Forsyth ¡
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 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 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
yi
yi
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
√ N
√ N corr({(xi, yi)}) = 1 N
N
yi
√ N ,
...
√ N
√ N ,
...
√ N
SLIDE 18 Inner ¡product ¡
✺ Inner ¡product’s ¡geometric ¡meaning: ¡ ✺ Lengths ¡of ¡both ¡vectors ¡
are ¡1 ¡
θ ¡ ν2 ¡ ν1 ¡
|ν1| |ν2| cos(θ)
ν1= ¡ ν2= ¡
√ N ,
...
√ N
√ N ,
...
√ N
SLIDE 19 Bound ¡of ¡correlation ¡coefficient ¡
θ ¡ ν2 ¡ ν1 ¡
|corr({(xi, yi)})| = |cos(θ)| ≤ 1
ν1= ¡ ν2= ¡
√ N ,
...
√ N
√ N ,
...
√ N
SLIDE 20
The ¡Properties ¡of ¡ ¡Correlation ¡ Coefficient ¡
✺ Symmetric ¡ ✺ Transla)ng ¡invariant ¡ ¡ ✺ Scaling ¡only ¡may ¡change ¡sign ¡ ✺ bounded ¡within ¡[-‑1, ¡1] ¡
¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
SLIDE 21 Using ¡correlation ¡to ¡predict ¡
¡
✺ Cau*on! ¡Correla)on ¡is ¡NOT ¡Causa)on ¡
Credit: ¡Tyler ¡ ¡Vigen ¡
SLIDE 22
How ¡do ¡we ¡go ¡about ¡the ¡prediction? ¡
✺ Removed ¡of ¡outliers ¡& ¡standardized ¡
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)}
p
SLIDE 24
Q: ¡
¡
✺ ¡Which ¡coordinates ¡will ¡you ¡use ¡for ¡the ¡
predictor ¡using ¡correla)on? ¡
¡
¡A. ¡ ¡Standard ¡coordinates ¡ ¡ ¡B. ¡ ¡Original ¡coordinates ¡ ¡ ¡
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
p
x + b
p = a
xi + b
ui = yi − yi
p =
yi − a xi − b
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 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 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 Here ¡is ¡the ¡linear ¡predictor! ¡
x
Correla)on ¡coefficient ¡
SLIDE 30 Prediction ¡Formula ¡
¡
✺ In ¡standard ¡coordinates ¡
¡
✺ In ¡original ¡coordinates ¡
r = corr({(xi, yi)})
p − mean({yi})
std({yi}) = r x0 − mean({xi}) std({xi})
p = r
x0
where ¡
SLIDE 31 Root-‑mean-‑square ¡(RMS) ¡prediction ¡ error ¡
Given var({ui}) = 1 − 2ar + a2 & a = r var({ui}) = 1 − r2
RMS error =
i })
¡
✺ ¡ ¡
¡
✺ ¡ ¡
= √ 1 − r2
=
SLIDE 32
See ¡the ¡error ¡through ¡simulation ¡
hUps://rpsychologist.com/d3/correla)on/ ¡
SLIDE 33 Example: ¡Body ¡Fat ¡data ¡
r ¡= ¡0.513 ¡
SLIDE 34 Example: ¡remove ¡2 ¡more ¡outliers ¡
r ¡= ¡0.556 ¡
SLIDE 35 Assignments ¡
✺ Reading ¡Chapter ¡2 ¡of ¡the ¡textbook ¡ ✺ Next ¡)me: ¡Probability ¡a ¡first ¡look ¡
¡
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
Acknowledgement ¡
Thank You!