标签:
当只有一个∑ 时,注意考虑到是矩阵,所以不用像神经网络一样sum
hx = X*theta; J = (1/(2*m))*(sum((hx-y).^2)); reg = lambda/(2*m)*sum(theta(2:end).^2); J = J + reg;
grad = (X‘ * (hx-y)) / m; grad(2:end) = grad(2:end)+ lambda * theta(2:end) / m;
标签:
原文地址:http://www.cnblogs.com/nice-day/p/5495980.html