ufldl学习笔记与编程作业:Logistic Regression(逻辑回归)

ufldl学习笔记与编程作业:Logistic Regression(逻辑回归)


ufldl出了新教程,感觉比之前的好,从基础讲起。系统清晰,又有编程实践。

在deep learning高质量群里面听一些前辈说。不必深究其它机器学习的算法,能够直接来学dl。

于是近期就開始搞这个了,教程加上matlab编程,就是完美啊。

新教程的地址是:http://ufldl.stanford.edu/tutorial/


本节学习链接:http://ufldl.stanford.edu/tutorial/supervised/LogisticRegression/


有了线性回归的基础再来学这个。简直是easy啊。

线性回归一般是拟合,预測的输出一般是连续的。

而逻辑回归通常来做离散的预測,比方二值的0或者1,也就是分类问题。


搞懂了目标函数和偏导数后,就能够编程了。


编程题目是对手写数字0和1做分类。

logistic_regression.m代码例如以下

function [f,g] = logistic_regression(theta, X,y)
  %
  % Arguments:
  %   theta - A column vector containing the parameter values to optimize.
  %   X - The examples stored in a matrix.  
  %       X(i,j) is the i'th coordinate of the j'th example.
  %   y - The label for each example.  y(j) is the j'th example's label.
  %

  m=size(X,2);
  
  % initialize objective value and gradient.
  f = 0;
  g = zeros(size(theta));
  
  h = sigmoid(X'*theta);
  f=-y*log2(h)+(1-y)*log2(1-h);
  g=X*(h-y');
  %
  % TODO:  Compute the objective function by looping over the dataset and summing
  %        up the objective values for each example.  Store the result in 'f'.
  %
  % TODO:  Compute the gradient of the objective by looping over the dataset and summing
  %        up the gradients (df/dtheta) for each example. Store the result in 'g'.
  %
%%% YOUR CODE HERE %%%

结果例如以下:


教程里说准确率应该是100%,我这里居然是99.7%和99.9%。

难道我做错了。。

假设由谁做到100%,记得告诉我啊。


本文作者:linger

本文链接:http://blog.csdn.net/lingerlanlan/article/details/38390085




posted @ 2017-05-25 14:43  wzzkaifa  阅读(216)  评论(0编辑  收藏  举报