Part Ⅳ
4.1 Words list
- logistic regression logistic 回归
- exponential family 指数族
- Newton’s method 牛顿方法
- generalized linear models 广义线性模型
4.2 The Newton’s method
The Newton’s method is a method for solving the root of an equation. Here’s a picture of the Newton’s method in action.
Newton’s method performs the following update:
θ : = θ − α f ( θ ) f ′ ( θ ) \theta := \theta - \alpha\frac{f(\theta)}{f^{'}(\theta)} θ:=θ−αf′(θ)f(θ).
Newton’s method gives a way of getting f ( θ ) = 0 f(\theta) = 0 f(θ)=0.What if we want to use it to maximize some functions ℓ \ell ℓ.The maximize of ℓ \ell ℓ correspond to points where its first derivative ℓ ′ ( θ ) ℓ′(θ) ℓ′(θ) is zero.And we obtain update rule:
θ : = θ − α ℓ ′ ( θ ) ℓ ′ ′ ( θ ) \theta := \theta - \alpha\frac{\ell^{'}(\theta)}{\ell^{''}(\theta)} θ:=θ−αℓ′′(θ)ℓ′(θ).
If θ \theta θ is a vector-value.The update rule is given by
θ : = θ − H − 1 ∇ θ ℓ ( θ ) \theta:=\theta-H^{-1}\nabla_{\theta}\ell(\theta) θ:=θ−H−1∇θℓ(θ).
4.3 The exponential family
The exponential family be written in the from
p ( y ; η ) = b ( y ) e x p ( η T T ( y ) − a ( η ) ) p(y; \eta) = b(y)exp(\eta^T T(y) - a(\eta)) p(y;η)=b(y)exp(ηTT(y)−a(η)).
Here, η \eta η is called the natural parameter (also called the canonical parameter) of the distribution; T ( y ) T(y) T(y) is the sufficient statistic (for the distributions we consider, it will often be the case that T ( y ) = y T(y) = y T(y)=y); and a ( η ) a(η) a(η) is the log partition function. The quantity e − a ( η ) e^{-a(\eta)} e−a(η)) essentially plays the role of a normalization constant, that makes sure the distribution p ( y ; η ) p(y; η) p(y;η) sums/integrates over y to 1.
Gaussian and Bernoulli are is familiar to us.They are proved to belong to the exponential family.
In the Bernoulli distribution:
T ( y ) = y T(y) = y T(y)=y.
b ( y ) = 1 b(y) = 1 b(y)=1.
a ( η ) = − l o g ( 1 − ϕ ) = l o g ( 1 + e − η ) a(\eta) = -log(1 - \phi) = log(1 + e^{-\eta}) a(η)=−log(1−ϕ)=log(1+e−η).
In the Gaussian distribution:
η = μ \eta = \mu η=μ.
T ( y ) = y T(y) = y T(y)=y.
a ( η ) = − μ 2 / 2 = − η 2 / 2 a(\eta) = -\mu^2/2 = -\eta^2/2 a(η)=−μ2/2=−η2/2.
b ( y ) = ( 1 / 2 π ) e x p ( ( − y 2 / 2 ) ) b(y) = (1/\sqrt{2\pi})exp((-y^2/2)) b(y)=(1/2π)exp((−y2/2)).
4.4 The generalized linear models
The generalized linear models is use to the prediction function of independent variable as the estimated value of dependent variable.
The generalized linear models are based on three assumptions:
- y ∣ x ; θ y | x; θ y∣x;θ ∼ Exponential Family ( η ) (η) (η). I.e., given x x x and θ θ θ, the distribution of y y y follows some exponential family distribution, with parameter η η η.
- Given x x x, our goal is to predict the expected value of T ( y ) T(y) T(y) given x x x.In most of our examples, we will have T ( y ) = y T(y) = y T(y)=y, so this means we would like the prediction h ( x ) h(x) h(x) output by our learned hypothesis h h h to satisfy h ( x ) = E [ y ∣ x ] h(x) = E[y|x] h(x)=E[y∣x]. (Note that this assumption is satisfied in the choices for h θ ( x ) h_\theta(x) hθ(x) for both logistic regression and linear regression. For instance, in logistic regression, we had h θ ( x ) = p ( y = 1 ∣ x ; θ ) = 0 ⋅ p ( y = 0 ∣ x ; θ ) + 1 ⋅ p ( y = 1 ∣ x ; θ ) = E [ y ∣ x ; θ ] . ) h_\theta(x) = p(y = 1|x; θ) = 0 · p(y = 0|x; θ) + 1 · p(y = 1|x; θ) = E[y|x; θ].) hθ(x)=p(y=1∣x;θ)=0⋅p(y=0∣x;θ)+1⋅p(y=1∣x;θ)=E[y∣x;θ].).
- The natural parameter η η η and the inputs x x x are related linearly: η = θ T x η = θ^Tx η=θTx.(Or, if η η η is vector-valued, then η i = θ i T x η_i = θ_i^T x ηi=θiTx).
There are three examples of the generalized linear models:
- Ordinary Least Squares.
According to assumption 2,we get:
h θ ( x ) = E [ y ∣ x ] h_\theta(x) = E[y|x] hθ(x)=E[y∣x].
Because of the Ordinary least Squares is satisfied Gaussian distribution so E [ y ∣ x ] = u E[y|x] = u E[y∣x]=u because of h θ ( x ) h_\theta(x) hθ(x) belong to the exponential family,so h θ ( x ) = μ = η h_\theta(x) = \mu = \eta hθ(x)=μ=η,according to assumption 3 we get h θ ( x ) = μ = η = θ T x h_\theta(x) = \mu = \eta = \theta^Tx hθ(x)=μ=η=θTx.
2.Logistic Regression.
We get the equation according to above three assumptions:
h θ ( x ) = E [ y ∣ x ; θ ] = ϕ = 1 / ( 1 + e − η ) = 1 / ( 1 + e − θ T x ) h_\theta(x) = E[y|x;\theta] = \phi = 1/(1 + e^{-\eta}) = 1/(1+e^{-\theta^Tx}) hθ(x)=E[y∣x;θ]=ϕ=1/(1+e−η)=1/(1+e−θTx).
3.Softmax Regression(For solving the multiple classification).
Softmax Regression is for solving the multiple classification. So the first of all,we need to prove it belong to exponential family.Then we can get:
η = [ l o g ( ϕ 1 / ϕ k ) l o g ( ϕ 2 / ϕ k ) ⋮ l o g ( ϕ k − 1 / ϕ k ) ] \eta = \left[\begin{matrix}log(\phi_1/\phi_k) \\ log(\phi_2/\phi_k) \\ \vdots\\ log(\phi_{k-1/}\phi_k)\end{matrix}\right] η=⎣⎢⎢⎢⎡log(ϕ1/ϕk)log(ϕ2/ϕk)⋮log(ϕk−1/ϕk)⎦⎥⎥⎥⎤.
a ( η ) = − l o g ( k ) a(\eta) = -log(k) a(η)=−log(k). b ( y ) = 1 b(y) = 1 b(y)=1.
because η i = l o g ϕ i ϕ k \eta_i = log\frac{\phi_i}{\phi_k} ηi=logϕkϕi,so
e η i = ϕ i / ϕ k e^{\eta_i} = \phi_i/\phi_k eηi=ϕi/ϕk.
ϕ i = e η i ϕ k \phi_i = e^{\eta_i}\phi_k ϕi=eηiϕk.
ϕ k ∑ i = 1 k e η i = ∑ i = 1 k ϕ i = 1 \phi_k\sum_{i=1}^{k}e^{\eta_i} = \sum_{i=1}^k\phi_i = 1 ϕk∑i=1keηi=∑i=1kϕi=1.
so the
ϕ i = e η i / ∑ j = 1 k e η j \phi_i = e^{\eta_i}/\sum_{j=1}^k e^{\eta_j} ϕi=eηi/∑j=1keηj.
we come to the conclusion
p ( y = i ∣ x ; θ ) = ϕ i p(y=i|x;\theta) = \phi_i p(y=i∣x;θ)=ϕi.
= e η i ∑ j = 1 k e η j =\frac{e^{\eta_i}}{\sum_{j=1}^k e^{\eta_j}} =∑j=1keηjeηi.
= e θ i T x ∑ j = 1 k e θ j T x =\frac{e^{\theta_i^Tx}}{\sum_{j=1}^k e^{\theta_j^Tx}} =∑j=1keθjTxeθiTx.
So our hypothesis will output:
h θ ( x ) = E [ T ( y ) ∣ x ; θ ] = [ ϕ 1 ϕ 2 ⋮ ϕ k − 1 ] h_\theta(x) = E[T(y)|x;\theta] = \left[\begin{matrix} \phi_1\\\phi_2\\ \vdots \\ \phi_{k-1}\end{matrix}\right] hθ(x)=E[T(y)∣x;θ]=⎣⎢⎢⎢⎡ϕ1ϕ2⋮ϕk−1⎦⎥⎥⎥⎤.
Hence,we can use the log-likelihood to solve the parameters of this model.
ℓ
(
θ
)
=
∑
i
=
1
m
l
o
g
p
(
y
(
i
)
∣
x
(
i
)
;
θ
)
\ell(\theta) = \sum_{i=1}^m logp(y^{(i)}|x^{(i)};\theta)
ℓ(θ)=∑i=1mlogp(y(i)∣x(i);θ).
=
∑
i
=
1
m
l
o
g
∏
l
=
1
k
(
e
θ
l
T
x
i
∑
j
=
1
k
e
θ
j
T
x
(
i
)
)
1
{
y
(
i
)
=
l
}
= \sum_{i=1}^m log \prod_{l=1}^k(\frac{e^{\theta_l^Tx^{i}}}{\sum_{j=1}^ke^{\theta_j^T x^{(i)}}})^{1\{y^{(i)}=l\}}
=i=1∑mlogl=1∏k(∑j=1keθjTx(i)eθlTxi)1{y(i)=l}.
Using a method such as gradient ascent or Newton’s method.