sigmoid.m
g = 1./(1+exp(-z));
costFunction.m
J = 1./m*(-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta))); grad = 1/m * X'*(sigmoid(X*theta) - y);
predict.m
J = 1./m*(-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta))); grad = 1/m * X'*(sigmoid(X*theta) - y);
costFunctionReg.m
[J, grad] = costFunction(theta, X, y); J = J + lambda/(2*m)*(sum(theta.^2) - theta(1).^2); %no need theta 1 grad = grad + lambda/m*theta; grad(1) = grad(1) - lambda/m*theta(1);
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Coursera机器学习week3 编程作业 - Python技术站