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(θ)=0f(\theta) = 0f(θ)=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)exp(ηTT(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)=yT(y) = yT(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)=yT(y) = yT(y)=y.
b(y)=1b(y) = 1b(y)=1.
a(η)=−log(1−ϕ)=log(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)=yT(y) = yT(y)=y.
a(η)=−μ2/2=−η2/2a(\eta) = -\mu^2/2 = -\eta^2/2a(η)=−μ2/2=−η2/2.
b(y)=(1/2π)exp((−y2/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 xxx and θθθ, the distribution of yyy follows some exponential family distribution, with parameter ηηη.
- Given xxx, our goal is to predict the expected value of T(y)T(y)T(y) given xxx.In most of our examples, we will have T(y)=yT(y) = yT(y)=y, so this means we would like the prediction h(x)h(x)h(x) output by our learned hypothesis hhh 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 xxx are related linearly: η=θTxη = θ^Txη=θTx.(Or, if ηηη is vector-valued, then ηi=θiTxη_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]=uE[y|x] = uE[y∣x]=u because of hθ(x)h_\theta(x)hθ(x) belong to the exponential family,so hθ(x)=μ=ηh_\theta(x) = \mu = \etahθ(x)=μ=η,according to assumption 3 we get hθ(x)=μ=η=θTxh_\theta(x) = \mu = \eta = \theta^Txhθ(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−θTx)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:
η=[log(ϕ1/ϕk)log(ϕ2/ϕk)⋮log(ϕ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(η)=−log(k)a(\eta) = -log(k)a(η)=−log(k). b(y)=1b(y) = 1b(y)=1.
because ηi=logϕiϕk\eta_i = log\frac{\phi_i}{\phi_k}ηi=logϕkϕi,so
eηi=ϕi/ϕke^{\eta_i} = \phi_i/\phi_keηi=ϕi/ϕk.
ϕi=eηiϕk\phi_i = e^{\eta_i}\phi_kϕi=eηiϕk.
ϕk∑i=1keηi=∑i=1kϕ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=1keη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;θ)=ϕip(y=i|x;\theta) = \phi_ip(y=i∣x;θ)=ϕi.
=eηi∑j=1keηj=\frac{e^{\eta_i}}{\sum_{j=1}^k e^{\eta_j}}=∑j=1keηjeηi.
=eθiTx∑j=1keθjTx=\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=1mlogp(y(i)∣x(i);θ)\ell(\theta) = \sum_{i=1}^m logp(y^{(i)}|x^{(i)};\theta)ℓ(θ)=∑i=1mlogp(y(i)∣x(i);θ).
=∑i=1mlog∏l=1k(eθlTxi∑j=1keθjTx(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.