吴恩达网课编程练习:
Programming Exercise 1: Linear Regression
warmUpExercise.m

function A = warmUpExercise()
A = eye(5);
end

plotData.m

function plotData(x, y)
figure   % open a new figure window
plot(x, y, 'rx', 'MarkerSize', 10); 
ylabel('Profit in $10,000s');
xlabel('Population of City in 10,000s');
end

computeCost.m

function J = computeCost(X, y, theta)
m = length(y); % number of training examples
J = 0;
J = 1/(2*m)*sum((X*theta-y).^2);
end

gradientDescent.m

function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
m = length(y); % number of training examples
J_history = zeros(num_iters, 1);
for iter = 1:num_iters
    for j=1:length(theta)
        thetanew(j) = theta(j)-alpha/m*sum((X*theta-y).*X(:,j));
    end
    theta = thetanew';
    J_history(iter) = computeCost(X, y, theta);
 end
 end


周志华西瓜书课后习题:
机器学习 学习打卡 D1

相关文章:

  • 2021-12-05
  • 2021-05-13
  • 2021-09-09
  • 2022-01-08
  • 2021-06-01
  • 2021-09-21
  • 2021-08-18
  • 2021-10-20
猜你喜欢
  • 2021-04-04
  • 2021-09-29
  • 2021-07-08
  • 2021-09-26
  • 2022-01-05
  • 2021-12-16
  • 2021-06-16
相关资源
相似解决方案