Calculate Sum of Square Error

38 ビュー (過去 30 日間)
Muhammad
Muhammad 2013 年 10 月 28 日
コメント済み: Carolyn 2022 年 12 月 12 日
% 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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 28 日
There is no y_bar in your code
Muhammad
Muhammad 2013 年 10 月 28 日
i know ! my question is this how to i calculate y_bar ?

サインインしてコメントする。

採用された回答

Wayne King
Wayne King 2013 年 10 月 28 日
編集済み: Wayne King 2013 年 10 月 28 日
You get the yhat values by plugging your observed X-values into the equation determined by your regression fit. You have an equation that comes from estimating the slope and the intercept.
yhat = slope*x+intercept
You have a vector of X-values, the values you used in determining the model fit in the first place. So you just plug that vector in your fitted equation and you will get a vector of yhat values equal in length to your observations, then just use the code I gave you above.
  2 件のコメント
Muhammad
Muhammad 2013 年 10 月 28 日
now i understand and feeling Stupid ! Thank u for u help :)
Carolyn
Carolyn 2022 年 12 月 12 日
y_bar is basically yhat, right?

サインインしてコメントする。

その他の回答 (1 件)

Wayne King
Wayne King 2013 年 10 月 28 日
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 件のコメント
Wayne King
Wayne King 2013 年 10 月 28 日
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
Muhammad 2013 年 10 月 28 日
i knw bro ! but how to i get these fitted values from eq_y ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRegression についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by