導(dǎo)師介紹的課程UFLDL(Unsupervised Feature Learning and Deep Learning)贰您。前一段時(shí)間寫了很多tensorflow方面的代碼良哲,但感覺在基礎(chǔ)知識(shí)方面還是有很多不足,因此重新?lián)炱疬@個(gè)課程來補(bǔ)補(bǔ)芋簿。
第一課講的是Linear Regression痒给,沒有做筆記就暫且挑過了说墨。
本節(jié)課講的是Logistic Regression。Logistic Regression其實(shí)是softmax 的一種苍柏。
在Logistic Regression中尼斧,使用sigmoid函數(shù),將feature的值約束到0试吁,1之間棺棵。
cost function
image.png
很容易可以化成矩陣的形式楼咳。
cost function對(duì)theta求導(dǎo),可以表示為:
image.png
化為矩陣容易表示的形式:
image.png
接下來介紹下作業(yè)的答案烛恤。
作業(yè)是對(duì)MNIST數(shù)據(jù)集總手寫的0和1進(jìn)行識(shí)別母怜。
ex1\logistic_regression_vec.m
function [f,g] = logistic_regression_vec(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));
prob = sigmoid(theta'*X);
f = -log(prob) * y' - log(1-prob) * (1-y)';
g = X * (prob-y)';
%
% TODO: Compute the logistic regression objective function and gradient
% using vectorized code. (It will be just a few lines of code!)
% Store the objective function value in 'f', and the gradient in 'g'.
%
%%% YOUR CODE HERE %%%
其中比較能夠體現(xiàn)矩陣運(yùn)算好處的部分就是y'或者(1-y)',直接將sum的功能包括在了矩陣運(yùn)算中缚柏。