Professional Documents
Culture Documents
clc
clear
close all
x=load('ex2x.dat');
y=load('ex2y.dat');
figure
plot(x,y,'o')
ylabel('Height in meters')
xlabel('Age in years')
%% linear regresion
theta = [0 0];
ss_old =theta;
ss_new = [inf inf];
alpha = 0.007;
while (abs(ss_new-ss_old)>0.0000000001)
ss_old = ss_new;
h_the = x*theta'; % prediction
theta(1)=theta(1)-alpha*(1/m).*sum(((h_the-y) .* x(:,1)));
theta(2)=theta(2)-alpha*(1/m).*sum(((h_the-y) .* x(:,2)));