李宏毅Machine Learning 学习笔记(1) Regression

1 Regression

Regression :outpur scalar

什么是回归?output是一个数值的就是回归。

Step 1: Model (function set )

A set of function

f 1 : y = 10.0 + 9.0 x c p

f 2 : y = 9.8 + 9.2 x c p

f 3 : y = 0.8 1.2 x c p

Linear Model

xi :输入值x的一个属性(feature 特征值)
wi :weight ,b :bias

y = b + w i x i

Step 2 : Goodness of function

y = b + w x c p

y hat 表示这是一个正确的数字
上标表示一个整体的资料,
下标表示这个资料里的某一个属性。

衡量function 需要 loss Function

Loss function

L ( f ) = n = 1 10 ( y ^ n f ( x c p n ) ) 2

Lost function 是 function 的 function

L(f) ——> L(w,b)

L ( f ) = L ( w , b ) = n = 1 10 ( y ^ n ( b + w x c p n ) ) 2

Step 3: Best function

pick the Best function

f = arg min f L ( f )

w , b = arg min w , b L ( w , b )

= arg min w , b n = 1 10 ( y ^ n ( b + w x c p n ) ) 2

Step 3: Gradient Descent

单个参数

w = arg min w L ( w )

  • pick an inital value w0
  • Compute

d L d W | w = w 0

w 1 w 0 η d L d W | w = w 0

  • Compute

d L d W | w = w 1

w 2 w 1 η d L d W | w = w 1

两个参数

w , b = arg min w , b L ( w , b )

  • pick an inital value w0
  • Compute (复习高等数学中如何求偏导)\

    L W | w = w 0 , b = b 0 , L b | b = b 0 , w = w 0 ,

    w 1 w 0 η L W | w = w 0 , b = b 0

    b 1 b 0 η L b | w = w 0 , b = b 0

  • Compute

L W | w = w 1 , b = b 1 , L b | b = b 1 , w = w 1 ,

w 2 w 1 η L W | b = b 1 , w = w 1

b 2 b 1 η L b | b = b 1 , w = w 1

Problem

globel minima
stuck at local minima
stuck at saddle point
very slow at the plateau

Linear Regression 的 lost function 是一个凸函数,不必担心局部最小值的问题

Learning Rate

η
Learning Rate 控制步子大小、学习速度。

another linear model

y = b + W 1 X c p + W 2 ( X c p ) 2

y = b + W 1 X c p + W 2 ( X c p ) 2 + W 3 ( X c p ) 3

y = b + W 1 X c p + W 2 ( X c p ) 2 + W 3 ( X c p ) 3 + W 4 ( X c p ) 4

y = b + W 1 X c p + W 2 ( X c p ) 2 + W 3 ( X c p ) 3 + W 4 ( X c p ) 4 + W 5 ( X c p ) 5

所谓一个model是不是linear 是指他的参数对他的output 是不是linear。
- A more complex model yields lower error on training data.
If we can truly find the best function

Model Selection

model Training Testing
1 31.9 35.0
2 15.4 18.4
3 15.3 18.1
4 14.9 28.2
5 12.8 232.1

- A more complex model does not always lead to better performance on testing data.
- This is Overfitting

复杂模型的model space涵盖了简单模型的model space,因此在training data上的错误率更小,但并不意味着在testing data 上错误率更小。模型太复杂会出现overfitting。

What are the hidden factors?

考虑pakemon种类对cp值的影响。

Back to step 1: Redesign the Model

i f x s = P i d g e y : y = b 1 + w 1 x c p

i f x s = W e e d l e : y = b 2 + w 2 x c p

i f x s = C a t e r p i e : y = b 3 + w 3 x c p

i f x s = E e v e e : y = b 4 + w 4 x c p

y = b 1 δ ( x s = P i d g e y ) + w 1 δ ( x s = P i d g e y ) x c p

+ b 2 δ ( x s = W e e d l e ) + w 2 δ ( x s = W e e d l e ) x c p

+ b 3 δ ( x s = C a t e r p i e ) + w 3 δ ( x s = P i d g e y ) x c p

+ b 4 δ ( x s = C a t e r p i e ) + w 4 δ ( x s = P i d g e y ) x c p

Training error = 3.8 ,Testing Error= 14.3

这个模型在测试集上有更好的表现。

Are there any other hidden factors?

hp值,体重,高度对cp值的影响。

Back to step 1: Redesign the Model Again

i f x s = P i d g e y : y , = b 1 + w 1 x c p + w 5 ( x c p ) 2

i f x s = W e e d l e : y , = b 2 + w 2 x c p + w 6 ( x c p ) 2

i f x s = C a t e r p i e : y , = b 3 + w 3 x c p + w 7 ( x c p ) 2

i f x s = E e v e e : y , = b 4 + w 4 x c p + w 8 ( x c p ) 2

y = y , + w 9 x n p + w 1 0 ( x n p ) 2 + w 1 x h + w 1 2 ( x h ) 2 + w 1 3 x w + w 1 4 ( x w ) 2

Training Error = 1.9, Testing Error = 102.3,Overfitting

如果同时考虑宝可梦的其它属性,选一个很复杂的模型,结果会overfitting。

Back to step 2:regularization

对很多不同的test 都general有用的方法:正则化。

L ( f ) = L ( w , b )
= n ( y ^ n ( b + w i x i ) ) 2 + λ ( w i ) 2

同时会让w很小。意味着,这是一个比较平滑的function。

y = b + w i x i

y + w i Δ x i = b + w i ( x i + Δ x i )

如果w1比较小的话,代表这个function是比较平滑的。

lambda Training Testing
0 1.9 102.3
1 2.3 68.7
10 3.5 25.7
100 4.1 11.1
1000 5.6 12.8
10000 6.3 18.7
100000 8.5 26.8

lambda 增加的时候,我们是会找到一个比较smooth的function。越大的λ,对training error考虑得越少。 调整λ,选择使testing error最小的λ。

猜你喜欢

转载自blog.csdn.net/songyuequan/article/details/80341092