我正在使用批量梯度下降实现逻辑回归.输入样本有两类要分类.类是1和0.在训练数据时,我使用以下sigmoid函数:
t = 1 ./ (1 + exp(-z));
Run Code Online (Sandbox Code Playgroud)
哪里
z = x*theta
Run Code Online (Sandbox Code Playgroud)
我使用以下成本函数来计算成本,以确定何时停止培训.
function cost = computeCost(x, y, theta)
htheta = sigmoid(x*theta);
cost = sum(-y .* log(htheta) - (1-y) .* log(1-htheta));
end
Run Code Online (Sandbox Code Playgroud)
我在每一步的成本都是NaN,因为htheta在大多数情况下,值为1或0.我该怎么做才能确定每次迭代的成本价值?
这是逻辑回归的梯度下降代码:
function [theta,cost_history] = batchGD(x,y,theta,alpha)
cost_history = zeros(1000,1);
for iter=1:1000
htheta = sigmoid(x*theta);
new_theta = zeros(size(theta,1),1);
for feature=1:size(theta,1)
new_theta(feature) = theta(feature) - alpha * sum((htheta - y) .*x(:,feature))
end
theta = new_theta;
cost_history(iter) = computeCost(x,y,theta);
end
end
Run Code Online (Sandbox Code Playgroud) matlab classification machine-learning gradient-descent logistic-regression
我理解由拉格朗日对偶和所有组成的整体 SVM 算法,但我无法理解为什么特别是支持向量的拉格朗日乘数大于零。
谢谢你。