Calculate Sum of Square Error
Ältere Kommentare anzeigen
% Extract Data from Excel sheet to Metrix
Metrix = xlsread('D:\data.xlsx');
% X represent annual franchise fee and Y represent start up cost ($1000) for a pizza franchise
X = Metrix(:,1);
Y = Metrix(:,2);
% as we know regression line eq is ---> y = wx+b where w is slope and b is y-intercept
SUMxy = sum(X.*Y);
SUMx = sum(X);
SUMy = sum(Y);
n = length(X);
SUMx2 = sum(X.*X);
SUMxthen2 = SUMx*SUMx;
slope_W = (((n)*(SUMxy)) - (SUMx*SUMy))/((n*SUMx2)-(SUMxthen2));
YIntercept_B = (SUMy/n)-(slope_W*(SUMx/n));
x=linspace(0,2000);
eq_y = slope_W*x+YIntercept_B;
scatter(X,Y,'*');
hold on;
plot(x,eq_y);
hold off;
as we know SSE = (y-y_bar)^2 .. but i have not a y_bar values how to i extract y_bar values in Matrix ?
4 Kommentare
Image Analyst
am 28 Okt. 2013
Please attach your spreadsheet so we can run your code.
Muhammad
am 28 Okt. 2013
Azzi Abdelmalek
am 28 Okt. 2013
There is no y_bar in your code
Muhammad
am 28 Okt. 2013
Akzeptierte Antwort
Weitere Antworten (1)
Wayne King
am 28 Okt. 2013
The sum of square error in regression is the 2-norm squared of the residuals, so if yhat are your fitted values, and y are the original observations, then
r = y-yhat;
SSE = norm(r,2)^2;
3 Kommentare
Muhammad
am 28 Okt. 2013
Wayne King
am 28 Okt. 2013
yhat are your fitted values. You have a regression equation, it's your eq_y the values of that equation are your predicted values
Muhammad
am 28 Okt. 2013
Kategorien
Mehr zu Linear Regression finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!