• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Liusy97
博客园    首页    新随笔    联系   管理    订阅  订阅

Machine Learning 第三周

ML week3 逻辑回归

Logistic Function

h_\theta(x)=g(\theta^Tx) 

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

image

当t大于0, 即下面公式成立时,y=1

\frac{1}{1+e^{-{\theta^Tx}}}>0.5 => {\theta^Tx}>0

关于theta与数据

y(x)=\theta_0+\theta_1x1+\theta_2x2

y(x)=\theta_0+\theta_1x_1+\theta_2x_2+\theta_3 x_1^2+\theta_4x_1x_2+\theta_5x_2^2

Cost function

由于使用线性回归的cost function会产生波浪形而达不到global最优点,所以使用新的方程

Cost(h_\theta(x),y) = -ylog(h_\theta(x))-(1-y)log(h_\theta(x))

多项式形式

image
image

矩阵形式

image

梯度下降算法

image

矩阵形式

image

使用其他更快的算法

function [jVal, gradient] = costFunction(theta)
  jVal = [...code to compute J(theta)...];
  gradient = [...code to compute derivative of J(theta)...];
end

options = optimset('GradObj', 'on', 'MaxIter', 100);
initialTheta = zeros(2,1);
   [optTheta, functionVal, exitFlag] = fminunc(@costFunction, initialTheta, options);

当y不止0,1时

如:天气有cloudy rainy sunny

问题:画出的线重复怎么办

image

过拟合


image

1)减少的特征:

  • 手动选择特征来保持。
  • 使用模型选择算法进行。(介绍 )

2)正规化

  • 保持所有的特征,但减小的幅度的参数θJ。
  • 正则化时,我们有许多稍微有益的特征
梯度下降防止过拟合

改变cost function

image

而梯度下降会变为

image

正规方程防止过拟合

image

posted @ 2018-04-16 17:29  Liusy97  阅读(198)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3