7月22日深度学习笔记——Regression
文章目录
前言
本文为7月22日深度学习笔记,分为五个章节:
- Step 1: Model;
- Step 2: Goodness of Function;
- Step 3: Find Best Function(Gradient Descent);
- Back to Step 1: Redesign;
- Back to Step 2: Regularization 正则化。
一、Step 1: Model
Estimating the combat power (CP) of a pokemon after evolution

y
=
b
+
w
⋅
x
c
p
.
y =b+w \cdot x_{cp}.
y=b+w⋅xcp.
- w: weight;
- b: bias.
二、Step 2: Goodness of Function
- A set of function: f 1 , f 2 … … f_1, f_2 …… f1,f2……
- function input: x 1 , x 2 … … x^1, x^2 …… x1,x2……
- function output: y ^ 1 , y ^ 2 … … \hat{y}_1, \hat{y}_2 …… y^1,y^2……
Training Data:
(
x
1
,
y
^
1
)
,
(
x
2
,
y
^
2
)
,
…
,
(
x
1
0
,
y
^
1
0
)
(x^1, \hat{y}_1) , (x^2, \hat{y}_2), …, (x^10, \hat{y}_10)
(x1,y^1),(x2,y^2),…,(x10,y^10)

- Loss function L L L:
- Input: a function
- output: how bad it is
L ( f ) = ∑ n = 1 10 ( y ^ n − f ( x c p n ) ) 2 L(f) = \sum_{n=1}^{10}(\hat{y}^n - f(x_{cp}^n))^2 L(f)=n=1∑10(y^n−f(xcpn))2
Where f ( x c p n ) f(x_{cp}^n) f(xcpn) is estimated y y y based on input function.
L ( f ) L(f) L(f) also equals:
L ( w , b ) = ∑ n = 1 10 ( y ^ n − ( b + w ⋅ x c p n ) ) 2 L(w, b) = \sum_{n=1}^{10}(\hat{y}^n - (b+w\cdot x_{cp}^n))^2 L(w,b)=n=1∑10(y^n−(b+w⋅xcpn))2

Each point in the figure is a function.
三、Step 3: Find Best Function(Gradient Descent)
How to pick the best function: gradient descent
f
∗
=
a
r
g
m
i
n
L
(
f
)
f* = arg\ min\ L(f)
f∗=arg min L(f)
w
∗
,
b
∗
=
a
r
g
m
i
n
L
(
w
,
b
)
=
a
r
g
m
i
n
∑
n
=
1
10
(
y
^
n
−
(
b
+
w
⋅
x
c
p
n
)
)
2
w*, b* = arg\ min\ L(w, b) = arg\ min\ \sum_{n=1}^{10}(\hat{y}^n - (b+w\cdot x_{cp}^n))^2
w∗,b∗=arg min L(w,b)=arg min n=1∑10(y^n−(b+w⋅xcpn))2
- 首先考虑1个参数
w
w
w 的情况:
- 取初始 w 0 w^0 w0;
- 在该点求导: d L d w ∣ w = w 0 \frac{dL}{dw}|_{w=w^0} dwdL∣w=w0
- 若为负,向右移动 w w w;
- 若为正,向左移动 w w w;
- w 0 − η d L d w ∣ w = w 0 → w 1 w^0-\eta\ \frac{dL}{dw}|_{w=w^0} → w^1 w0−η dwdL∣w=w0→w1, η \eta η is “learning rate”;
- w 1 − η d L d w ∣ w = w 1 → w 2 w^1-\eta\ \frac{dL}{dw}|_{w=w^1} → w^2 w1−η dwdL∣w=w1→w2,以此类推;

- 当有2个参数
w
,
b
w, b
w,b 的情况:
- g r a d i e n t = ∂ L ∂ w , ∂ L ∂ b gradient = \frac{\partial L}{\partial w}, \frac{\partial L}{\partial b} gradient=∂w∂L,∂b∂L;
- w 0 − η ∂ L ∂ w ∣ w = w 0 → w 1 w^0-\eta\ \frac{\partial L}{\partial w}|_{w=w^0} → w^1 w0−η ∂w∂L∣w=w0→w1;
- b 0 − η ∂ L ∂ b ∣ b = b 0 → b 1 b^0-\eta\ \frac{\partial L}{\partial b}|_{b=b^0} → b^1 b0−η ∂b∂L∣b=b0→b1

-
**Results: **
A v e r a g e E r r o r o n T e s t i n g D a t a = 1 10 ∑ n = 1 10 e n Average\ Error\ on\ Testing\ Data = \frac{1}{10} \sum_{n=1}^{10}e^n Average Error on Testing Data=101n=1∑10en -
Model Selection:

但是,a more complex model does not always lead to better performance, which is Overfitting
四、 Back to Step 1: Redesign
- Find the hidden factors.

x s = s p e c i e s o f x δ ( x s = P i d g e y ) { = 1 i f x s = P i d g e y = 0 o t h e r w i s e x_s = species\ of \ x \\ \delta (x_s=Pidgey) \begin{cases} =1\ if x_s=Pidgey \\ =0\ otherwise \end{cases} xs=species of xδ(xs=Pidgey){=1 ifxs=Pidgey=0 otherwise


五、Back to Step 2: Regularization 正则化
y
=
b
+
∑
w
i
x
i
L
=
∑
n
(
y
^
n
−
y
)
2
+
λ
∑
(
w
i
)
2
y=b+\sum w_ix_i \\ L= \sum_{n}(\hat{y}^n-y)^2+\lambda \sum (w_i)^2
y=b+∑wixiL=n∑(y^n−y)2+λ∑(wi)2

- Smaller w i w_i wi means smoother;
- But don’t be too smooth.
六、Error
来源:
- bias;
- variance.
Bias and Variance of Esitimator:
A variable x:
- μ \mu μ: the mean of x;
- σ 2 \sigma^2 σ2: the variance(方差)of x;
- Estimator(期望) of
μ
\mu
μ:
m = 1 N ∑ n x n ≠ μ E [ m ] = E [ 1 N ∑ n x n ] = 1 N ∑ n E [ x n ] = μ m=\frac{1}{N}\sum_{n}x^n\ne \mu\\ E[m]=E[\frac{1}{N}\sum_{n}x^n]=\frac{1}{N}\sum_{n}E[x^n]=\mu m=N1n∑xn=μE[m]=E[N1n∑xn]=N1n∑E[xn]=μ - Variance depends on the number of samples:
V a r [ m ] = σ 2 N s = 1 N ∑ n ( x n − m ) 2 Var[m]=\frac{\sigma^2}{N}\\ s=\frac{1}{N}\sum_{n}(x^n-m)^2 Var[m]=Nσ2s=N1n∑(xn−m)2 - Biased estimator 偏差估计量:
s = 1 N ∑ n ( x n − m ) 2 E [ s ] = N − 1 N σ 2 ≠ s i g m a 2 s=\frac{1}{N}\sum_{n}(x^n-m)^2\\ E[s]=\frac{N-1}{N}\sigma^2\ne sigma^2 s=N1n∑(xn−m)2E[s]=NN−1σ2=sigma2



- What to do with large bias:
- model cannot fit the training examples ⇒ Uderfitting, large bias ⇒ add more features + a more complex model
- model fit the training examples, but large on testing data ⇒ Overfitting, large variance ⇒ more data(not always practical) + regularization(may increase bias)
更多推荐
所有评论(0)