问题描述
- 如何使用octave对逻辑回归实现所有列子
-
我正在学习吴恩达老师的machine learing,在用octave实现逻辑回归时发现代价函数并不能对所有列子都通用,请各位帮帮忙,要实现的函数:
function [J, grad] = costFunction(theta, X, y) m = length(y); % number of training examples J = 0; grad = zeros(size(theta)); predictions = 0; for i = 1:m J = J + (-y(i,:) * log(sigmoid (X(i,:)*theta))) - (1-y(i,:)) * log(1-sigmoid (X(i,:)*theta)); end predictions = sum(sigmoid (X*theta)) - y; grad = predictions'* X / m; J = J/m;
解决方案
http://blog.sina.com.cn/s/blog_890c6aa301015mya.html
时间: 2024-11-02 13:32:30