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);

 

相关文章:

  • 2021-06-06
  • 2021-08-26
  • 2021-09-16
  • 2021-09-14
  • 2022-12-23
  • 2021-06-18
  • 2021-04-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案