Linear regression in is an approach to modeling the relation between a scalar variable y and another variable x.The linear regression involves an analysis of a set of data so as to arrive at an approximate relation between the data so that further predictions of values of y corresponding to the given values of x become possible.
Regression analysis can be done in a number of methods.In linear regression analysis we attempt to arrive at a linear equation of the form y=bx+a so as to model the data.
The values of b,slope and a,y intercept can be found with the help of the following relation
Now the equation defines a straight line so that the distance between the line and the given points in minimum.
Once the values of a and b available the prediction is possible using the equation
y=a+bx
Implementation using octave.
The linear regression analysis is implemented using 2 functions..predict() and value()
The predict function takes a nx2 matrix as argument.The elements of the matrix is the arranged such that each row corresponds to a pair of data ie x and y .
The code can be written as..
unction predict(a)
x=0;
y=0;
xy=0;
xx=0;
yy=0;
for i=1:size(a,1)
x=x+a(i,1);
y=y+a(i,2);
xx=xx+(a(i,1)^2);
yy=yy+(a(i,2)^2);
xy=xy+(a(i,1)*a(i,2));
endfor
m=0;
c=0;
n=size(a,1);
c= ((y*xx)-(x*xy))/((n*xx)-(x*x));
m= ((n*xy)-(x*y))/((n*xx)-(x*x));
save("c.mat");
save("m.mat");
end
function [y]=value(q)
load("c.mat");
load("m.mat");
y=(m*q)+c;
end
Regression analysis can be done in a number of methods.In linear regression analysis we attempt to arrive at a linear equation of the form y=bx+a so as to model the data.
The values of b,slope and a,y intercept can be found with the help of the following relation
Now the equation defines a straight line so that the distance between the line and the given points in minimum.
Once the values of a and b available the prediction is possible using the equation
y=a+bx
Implementation using octave.
The linear regression analysis is implemented using 2 functions..predict() and value()
The predict function takes a nx2 matrix as argument.The elements of the matrix is the arranged such that each row corresponds to a pair of data ie x and y .
The code can be written as..
unction predict(a)
x=0;
y=0;
xy=0;
xx=0;
yy=0;
for i=1:size(a,1)
x=x+a(i,1);
y=y+a(i,2);
xx=xx+(a(i,1)^2);
yy=yy+(a(i,2)^2);
xy=xy+(a(i,1)*a(i,2));
endfor
m=0;
c=0;
n=size(a,1);
c= ((y*xx)-(x*xy))/((n*xx)-(x*x));
m= ((n*xy)-(x*y))/((n*xx)-(x*x));
save("c.mat");
save("m.mat");
end
function [y]=value(q)
load("c.mat");
load("m.mat");
y=(m*q)+c;
end
0 comments:
Post a Comment