TensorFlow-2-概念1

机器学习分类的基础概念。

1.特征缩放

1.1 调节比例(Rescaling)

这种方法是将数据的特征缩放到[0,1]或[-1,1]之间。缩放到什么范围取决于数据的性质。对于这种方法的公式如下:
$$x’ = \frac{x - min(x)}{max(x) - min(x)}$$

1.2 标准化(Standardization)

$$
x’ = \frac{x - \bar x}{\sigma}
$$
方差

2.正规方程求解

有时使用正规方程求解会是更好地方案:

$$
\theta=(X^TX)^{-1}X^Ty
$$

3.逻辑回归

3.1模型

$$
0<=h_{\theta}(x)<=1
$$
$$
h(\theta)=g(\theta^Tx)
$$
estimate probability that y=1 on input x

Sigmod(Logistic) function:

$$
g(z) = \frac{1}{1+e^{-z}}
$$

3.2判定边界

决定何时的模型和参数,能够对进行分类操作。

在这种情况下,平方差的代价函数就不再适用,我们重新定义代价函数:

$$
J(\theta)=frac{1}{m}\sum_{i=1}^mCost(h_\theta(x^{(i)}),y^{(i)})
$$
其中:

$$
Cost(h_\theta(x),y)=
\begin{cases}
-log(h_\theta(x)) & \text {if y = 1}\
-log(1-h_\theta(x)) & \text {if y = 0}
\end{cases}
$$
代价函数说明:
当实际的y=1并且$h_\theta$也是1时,误差为0,当y=1但$h_\theta$不为1时误差随着$h_\theta$的变小而变大;当实际的y=0且$h_\theta$也为0时代价为0,当y=0,但$h_\theta$不为0时误差随着$h_\theta$的变大而变大。

再次进行简化,那么我们的代价函数Cost为:

$$
Cost(h_\theta(x),y)=-ylog(h_\theta(x))-(1-y)log(1-h_\theta(x))
$$
代入到代价函数得到:

$$
J(\theta)=-\frac{1}{m}\sum_{i=1}^my^{(i)}*log(h_\theta(x^{(i)})+(1-y^{(i)})log(1-h_\theta(x^{(1)})))
$$

那么在我们得到代价函数后,我们就能够使用梯度下降算法来使得我们的代价函数最小:
Repeat{

$$
\theta_j:=\theta_j-\alpha\frac{\partial}{\partial\theta_j}J(\theta)
$$

}
同样在此处也需要注意同时更新的问题。

4.简化代价函数

$$
\theta_j:=\theta_j-\alpha\frac{\partial}{\partial\theta_j}J(\theta)
$$
$\theta$更新过程:
推导过程
所以最后$\theta$为:

$$
\theta_j:=\theta_j-\alpha\frac{1}{m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})x^{(i)}_j
$$

梯度下降并不是唯一的算法,还存在:

  • 共轭梯度法
  • BFGS(变尺度法)
  • L-BFGS(限制变尺度法)

5.分类1 VS N

版权声明:本文为博主原创文章,转载需声明为转载内容并添加原文地址。

原文地址:https://coderdock.com

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2017-2020 Dock
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信