03 Logistic Regression
Posted qq-1615160629
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了03 Logistic Regression相关的知识,希望对你有一定的参考价值。
Binary Classification
Define
Sigmoid Function
Logistic Function
\[ h_\theta(x) = g(\theta^Tx) \]
\[ z = \theta^Tx \]
\[ 0 <= g(z) = \frac11 + e^-z <= 1 \]\( h_\theta(x) \) the probability that the output is 1.
\( h_\theta(x) = P(y = 1 | x; \theta) \)
\( P(y = 0 | x; \theta) + P(y = 1 | x; \theta) = 1 \)
设置 0.5为判定边界,则 \(h_\theta(x)=0.5 <==> \theta^Tx = 0\)
Cost Function
- \[J(\theta) = \dfrac1m \sum_i=1^m \mathrmCost(h_\theta(x^(i)),y^(i))\]
- \[ \mathrmCost(h_\theta(x),y) = -\log(h_\theta(x)) ,\textif y = 1 \]
- \[ \mathrmCost(h_\theta(x),y) = -\log(1-h_\theta(x)), \textif y = 0 \]
- \[ Cost(h_\theta(x), y) = -ylog(h_\theta(x)) - (1 - y)log(1 - h_\theta(x)) \]
Algorithm
\(\beginalign* & Repeat \; \lbrace \newline & \; \theta_j := \theta_j - \frac\alpham \sum_i=1^m (h_\theta(x^(i)) - y^(i)) x_j^(i) \newline & \rbrace \endalign*\)
- 虽然跟梯度下降相同但两者\(h_\theta(x)\)的定义并不相同
逻辑回归也可以通过特征缩放来加快收敛速度
可用于计算 \(\theta\) 的算法
- Gradient descent
- Conjugate gradient
- BFGS 共轭梯度法(变尺度法)
- L-BFGS 限制变尺度法
- 后三种算法的特性
Advantages:
a.no need to manually pick \(\alpha\)
b.often faster than gradient descent
Disadvantages:
More complexOctave 的优化算法使用
%exitFlag: 1 收敛
%R(optTheta) >= 2
options = optimset(‘GradObj’, ‘on’, ‘MaxIter’, ‘100’);
initialTheta = zeros(2, 1);
[optTheta, functionVal, exitFlag] ...
= fminumc(@costFunction, initialTheta, options);
%costFunction:
function [jVal, gradient] = costFunction(theta)
jVal = ... %cost function
gradient = zeros(n, 1); %gradient
gradient(1) = ...
...
gradient(n) = ...
Multi-class classification
one-vs-all one-vs-rest
- Train a logistic regression classifier \(h_\theta^(i)(x)\) for each class \(i\) to predict the probability that \(y = i\).
- On a new input \(x\), to make a prediction, pick the class \(i\) that maximizes \(\max \limits_ih_\theta^(i)(x)\).
以上是关于03 Logistic Regression的主要内容,如果未能解决你的问题,请参考以下文章
Logistic Regression Cifar10- 使用 tensorflow 1.x 的图像分类
机器学习实战python3 Logistic Regression
机器学习实验四基于Logistic Regression二分类算法实现手部姿态识别
Tensorflow逻辑斯特回归(Logistic Regression)的简单实现
R构建Logistic回归实战(Logistic Regression)
python逻辑回归(logistic regression LR) 底层代码实现 BGD梯度下降算法 softmax多分类