hey ,i am using this function to implement gradient descent but it returns only the theta value not the J_history value,Please help me in this situtation
    조회 수: 4 (최근 30일)
  
       이전 댓글 표시
    
function [theta,J_history] = gradientDescent(X, y, theta, alpha, num_iters)
% Initialize some useful values
m = length(y); % number of training examples
J_history = zeros(num_iters, 1);
for iter = 1:num_iters
    a1=(X*theta-y);
    a2=(X*theta-y).*X;
    theta(1)=theta(1)-alpha*sum(sum(a1))*(1/m);
    theta(2)=theta(2)-alpha*sum(sum(a2))*(1/m);
    % Save the cost J in every iteration    
    J_history(iter) = computeCost(X, y, theta);
end
end
댓글 수: 0
답변 (1개)
  Rohit Kulkarni
      
 2022년 7월 2일
        
      편집: Rohit Kulkarni
      
 2022년 7월 2일
  
      Hi Ashok, 
Are you facing this same issue :
The answer to this may solve your problem.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!