Professional Documents
Culture Documents
Vmls Slides Lect13
Vmls Slides Lect13
Vmls Slides Lect13
Validation
Feature engineering
y ⇡ f (x)
I A = 1, so
✓ˆ1 = (1T 1) 1 1T yd = (1/N)1T yd = avg(yd )
I the mean of y (1) , . . . , y (N) is the least squares fit by a constant
I we can plot the data (xi , yi ) and the model function ŷ = f̂ (x)
d std(yd )
f̂ (x) = avg(y ) + ⇢ (x avg(xd ))
std(xd )
f̂ (x)
ŷ = (rrf + ↵) + (x µmkt )
90 6
Petroleum consumption
(million barrels per day)
80 4
2
70
0
60
2
0
85
90
95
00
05
10
15
80
85
90
00
05
10
15
8
9
19
19
19
19
20
20
20
20
19
19
19
19
20
20
20
20
Year Year
I fi (x) = xi 1 , i = 1, . . . , p
I model is a polynomial of degree less than p
f̂ (x) = ✓ 1 + ✓ 2 x + · · · + ✓ p xp 1
I A is Vandermonde matrix
26 1 x (1) ··· (x (1) ) p 1 37
66 77
x (2) (x (2) ) p 1
A = 666 77
1 ···
66
.. .. .. 77
77
. . .
64 1 x (N) ··· (x (N) ) p 1
5
x x
degree 10 degree 15
f̂ (x) f̂ (x)
x x
Introduction to Applied Linear Algebra Boyd & Vandenberghe 13.15
Regression as general data fitting
f1 (x) = 1, fi (x) = xi 1 , i = 2, . . . , n + 1
so model is
ŷ = ✓ 1 + ✓ 2 x1 + · · · + ✓ n+1 xn = xT ✓ 2:n + ✓ 1
I = ✓ 2:n+1 , v = ✓ 1
I time zeries z1 , z2 , . . .
ẑt+1 = ✓ 1 zt + · · · + ✓ M zt M+1 , t = M, M + 1, . . .
I M is memory of model
I ẑt+1 is prediction of next value, based on previous M values
I we’ll choose to minimize sum of squares of prediction errors,
solid line shows one-hour ahead predictions from AR model, first 5 days
70
Temperature ( F)
65
60
55
20 40 60 80 100 120
k
Validation
Feature engineering
basic idea:
I goal of model is not to predict outcome for the given data
I instead it is to predict the outcome on new, unseen data
I (can also compare RMS prediction error on train and test data)
models fit using training set of 100 points; plots show test set of 100 points
degree 2 degree 6
f̂ (x) f̂ (x)
x x
degree 10 degree 15
f̂ (x) f̂ (x)
x x
Introduction to Applied Linear Algebra Boyd & Vandenberghe 13.25
Example
1
Train
Test
0.8
Relative RMS error
0.6
0.4
0.2
0 5 10 15 20
Degree
Validation
Feature engineering
ŷ = ✓ 1 f1 (x) + · · · + ✓ p fp (x)
(xi bi )/ai
– bi ⇡ mean value of the feature across the data
– ai ⇡ standard deviation of the feature across the data
new features are called z-scores
log(1 + xi )