L3 Assessingperformance Errors Biasvar Annotated
L3 Assessingperformance Errors Biasvar Annotated
Regression:
Predicting House Prices
STAT/CSE 416: Intro to Machine Learning
Emily Fox
University of Washington
April 3, 2018
©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
Feature x ML ŷ
Training
extraction model
Data
y ⌃
f
ML algorithm
Quality
metric
2 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
1
4/3/18
Hi ML expert,
here is a data
table to analyze
h(x)
Feature ML ŷ
Training
extraction model
Data
y ŵ
ML algorithm
Quality
metric
4 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
2
4/3/18
f(x) = w0+w1 x
parameters
square feet (sq.ft.) x of model
6 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
3
4/3/18
Input? Output?
feature 1 = parameter 1 = w0
feature 2 = parameter 2 = w1
f(x) = w0 + w1 x+ w2 x2 + … + wp xp
4
4/3/18
Polynomial regression
Model:
yi = w0 + w1 xi+ w2 xi2 + … + wp xip + εi
Input? Output?
feature 1 = parameter 1 = w0
feature 2 = parameter 2 = w1
feature 3 = parameter 3 = w2
… …
feature p+1 = parameter p+1 = wp
9 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
5
4/3/18
x[2]
s
o m
ro
th
ba
#
square feet (sq.ft.) x[1]
11 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
Input? Output?
feature 1 = parameter 1 = w0
feature 2 = parameter 2 = w1
feature 3 = parameter 3 = w2
6
4/3/18
h(x)
Feature ML ŷ
Training
extraction model
Data
y ŵ
ML algorithm
Quality
metric
14 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
7
4/3/18
RSS(w) = (yi- )2
price ($)
x[2]
s
om
ro
th
ba
#
h(x)
Feature ML ŷ
Training
extraction model
Data
y ŵ
ML algorithm
Quality
metric
16 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
8
4/3/18
Gradient descent
Algorithm:
h(x)
Feature ML ŷ
Training
extraction model
Data
y ŵ
ML algorithm
Quality
metric
18 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
9
4/3/18
Compact notation
D
X
f(xi) = w0 h0(xi) + w1 h1(xi) + … + wD hD(xi) = wj hj(xi)
j=0
1 0 0 0 5 3 0 0 1 0 0 0 0
3 0 0 0 2 0 0 1 0 1 0 0 0
10
4/3/18
predicted
change in $
1 sq. ft.
x[2]
s
om
ro
th
ba
#
11
4/3/18
predicted
change in $
For fixed
1 bathroom # sq.ft.!
# bathrooms x[2]
23 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
x[2]
s
om
ro
th
ba
#
12
4/3/18
y
price ($)
square feet x
25
(sq.ft.) STAT/CSE 416: Intro to Machine Learning
©2018 Emily Fox
13
4/3/18
SWITCH TO IPYNB
14
4/3/18
RSS(w0,w1) = (yi-[w0+w1xi])2
15
4/3/18
16
4/3/18
Assessing Performance
STAT/CSE 416: Intro to Machine Learning
Emily Fox
University of Washington
April 3, 2018
©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
Fit f
17
4/3/18
Measuring loss
Loss function: Cost of using ŵ at x
when y is true
L(y,fŵ(x))
actual
f(x) = predicted value ŷ
value
18
4/3/18
Dude, it’s
not a linear
relationship!
square feet (sq.ft.) x
37 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
Dude, it’s
not a linear
relationship!
square feet (sq.ft.) x
38 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
19
4/3/18
I can
minimize
your RSS
square feet (sq.ft.) x
39 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
My house
isn’t worth
so little
20
4/3/18
Minimizes RSS,
but bad predictions
21
4/3/18
22
4/3/18
23
4/3/18
Example:
Fit quadratic to minimize RSS
y
price ($)
ŵ minimizes
RSS of
training data
square feet (sq.ft.) x
47 ©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
2. Training error
= avg. loss on houses in training set
N
1 X
= L(yi,fŵ(xi))
N i=1
24
4/3/18
Example:
Use squared error loss (y-fŵ(x))2
y
price ($)
Example:
Use squared error loss (y-fŵ(x))2
y
Training error (ŵ) =
N
1 X
(yi-fŵ(xi))2
price ($)
N i=1
RMSE
v =
u N
u1 X
t (y -f (x ))2
N i=1 i ŵ i
25
4/3/18
y
Error
price ($)
square feet (sq.ft.) x
Model complexity
y
Error
price ($)
26
4/3/18
y
Error
price ($)
square feet (sq.ft.) x
Model complexity
y
Error
price ($)
27
4/3/18
y Model complexity y
y
price ($)
56
square feet (sq.ft.) x
©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
28
4/3/18
y
price ($)
xt
57
square feet (sq.ft.) x
©2018 Emily Fox STAT/CSE 416: Intro to Machine Learning
29
4/3/18
Generalization error
Lots of houses
in neighborhood,
but not in dataset
30
4/3/18
For fixed
# sq.ft.
price ($)
31
4/3/18
y
Error
fŵ
price ($)
32
4/3/18
y
Error
fŵ
price ($)
square feet (sq.ft.) x
Model complexity
y fŵ
Error
price ($)
33
4/3/18
y fŵ
Error
price ($)
square feet (sq.ft.) x
Model complexity
y
Error
fŵ
price ($)
34
4/3/18
Can’t
Error
compute!
y Model complexity y
35