### 线性回归(Regression)

linear regression
logistic regression
softmax regression

#@author:       gr
#@date:         2014-01-21
#@email:        forgerui@gmail.com

一、linear regression

线性模型:

\[h_\theta(x) = \theta^T X \]

代价函数:
代价函数使用平方误差损失函数。

\[\min_\theta J(\theta) = \dfrac{1}{2} \sum_{i=1}^m(h_\theta(x^{(i)}) - y^{(i)})^2 \]

求解:
可以使用最小二乘法和梯度下降法。
最小二乘法:

\[\theta = (X^TX)^{-1}X^T \overrightarrow y \]

梯度下降法:
批梯度下降,增量梯度下降。更新参数,以使代价函数最小化。

二、logistic regression

逻辑回归模型:
输出 \(Y=1\) 的对数几率是由输入 \(x\) 的线性函数表示的模型,即logistic regression

\[P(Y=1 \mid x) = \dfrac{1}{1+e^{-z}} = \dfrac{1}{1 + e^{-w \cdot x}} = \dfrac{e^{w \cdot x}}{1 + e^{w \cdot x}} \]

\[P(Y=0 \mid x) = 1- P(Y=1 \mid x) = \dfrac{1}{1 + e^{w \cdot x}} \]

求事件的对数几率:

\[logit(p) = log\dfrac{p}{1-p} = w \cdot x \]

对数几率是一个关于x的线性函数。

模型参数估计:
逻辑回归的参数估计可以采用极大似然估计求得。

$$\begin{align*} l(\theta) = & \Pi_{i=1}^N (p_i)^{y_i}(1-p_i)^{1-y_i} \\ = & \sum_{i=1}^{N} [y_i\log{(p_i)} + (1-y_i)\log{(1 - p_i)}] \\ = & \sum_{i=1}^{N} [ y_i \log{(\dfrac{p_i}{1-p_i})} + \log{(1-p_i)}] \\ = & \sum_{i=1}^N [y_i(w \cdot x_i) - \log{(1 + e^{(w \cdot x )})}] \end{align*} $$

\(L(w)\)求极大值,就可以得到\(w\)的估计值。用梯度下降法或拟牛顿法求解。

损失函数:

  1. Gold Standard
  2. Hinge Loss
    SVM
  3. Log Loss
    Logistic RegressionSoftmax Regression
  4. Squared Loss
    Linear Regression
  5. Boosting

代价函数:
这里使用对数函数作为损失函数:

\[J(\theta) = -\dfrac{1}{m}[ ~ \sum_{i=1}^m y_i\log(h_\theta(x_i)) + (1-y_i)\log(1-h_\theta(x_i)) ~] \]

用梯度下降法或拟牛顿法求解。

三、softmax regression

模型:
对于多分类问题,\(y_i \in \{ 1, 2, \cdots , k\}\)。对于其中一类作为positive,则另外的k-1类就为negative。

$$ \begin{align*} h_\theta(x^{(i)}) = & \left[ \begin{array}{c} p(y^{(i)} = 1 \mid x^{(i)}, \theta) \\ p(y^{(i)} = 2 \mid x^{(i)}, \theta) \\ \vdots \\ p(y^{(i)} = k \mid x^{(i)}, \theta) \\ \end{array} \right] \\ = & \dfrac{1}{\sum_{j=1}^k e^{\theta_j^Tx^{(i)}}} \left[ \begin{array}{c} e^{\theta_1^T x^{(i)}} \\ e^{\theta_2^T x^{(i)}} \\ \vdots \\ e^{\theta_k^T x^{(i)}} \\ \end{array} \right] \end{align*} $$

\(\theta\)\(\theta_1,\theta_2, \ldots \theta_K\)罗列起来:

\[\theta = \left[ \begin{array}{c} \theta_1^T \\ \theta_2^T \\ \vdots \\ \theta_k^T \end{array} \right]\]

得到softmax回归的代价函数:

\[J(\theta) = -\dfrac{1}{m} [~ \sum_{i=1}^m \sum_{j=1}^k 1 \{y^{(i)} = j\}\log{\dfrac{e^{\theta_j^T x^{(i)}}}{\sum_{l=1}^k e^{\theta_l^Tx^{(i)}}}} ~] \]

可以看出softmax是logistic的推广,同样用梯度下降法或拟牛顿法求解。

Reference

  1. http://www.cnblogs.com/bzjia-blog/p/3366780.html
  2. http://www.cnblogs.com/bzjia-blog/p/3370869.html
  3. 李航 著 《统计学习方法》
  4. http://blog.csdn.net/viewcode/article/details/8794401
  5. http://blog.csdn.net/abcjennifer/article/details/7716281
  6. Deva Ramanan 《Machine Learning》 Lecture1
posted @ 2015-01-31 21:50  bairuiworld  阅读(247)  评论(0编辑  收藏  举报