Create a Model to Predict Data.

Hi,
I'm given the data attached and I need to create a model to predict % Body Fat from a linear combination of Waist, Weight, and offset. So far, I have reordered the Waist in numerical order and then created a scatter plot as you can see in the code below. I am not sure how to proceed from here.
Waist=[32 32 33 33 33 34 34 35 36 36 38 38 38 39 40 40 41 41 44 44];
Weight=[175 168 159 188 188 159 146 173 181 175 200 187 188 196 192 240 205 215 246 219]
scatter(Waist, Weight)
xlabel ('Waist (in)')
ylabel ('Weight (lb)')
Thank you so much in advance!!

 採用された回答

Star Strider
Star Strider 2017 年 2 月 11 日

1 投票

Here you go. I also typed in the ‘Body Fat %’ for you. That is sort of necessary if you want to use it in your equation.
I prefer stem3 to scatter3 because it gives a better sense of the (x,y) relationships of the data.
The Code
Waist=[32 32 33 33 33 34 34 35 36 36 38 38 38 39 40 40 41 41 44 44];
Weight=[175 168 159 188 188 159 146 173 181 175 200 187 188 196 192 240 205 215 246 219];
BF_Pct = [6 21 15 6 22 31 32 21 25 30 10 20 22 9 38 10 27 12 10 28];
Design_Matrix = [ones(size(Waist(:))), Waist(:), Weight(:)]; % Design Matrix
B = Design_Matrix\BF_Pct(:); % Estimate Parameters
BF_Pct_Est = Design_Matrix*B; % Fit Equation
figure(1)
stem3(Waist(:), Weight(:), BF_Pct(:), '-b', 'filled')
hold on
stem3(Waist(:), Weight(:), BF_Pct_Est(:), '-pg', 'filled')
hold off
xlabel ('Waist (in)')
ylabel ('Weight (lb)')
zlabel('Body Fat Percent')
grid on
legend('Data', 'Regression Fit')
view([-20 +24])

4 件のコメント

newbie
newbie 2017 年 2 月 11 日
Thank you so much Star Strider!!!!
Now from here, how would I calculate the slope, if it's not too much trouble to ask.
Star Strider
Star Strider 2017 年 2 月 11 日
My pleasure!
The slopes (there are two, creating a plane) are ‘B(2)’ and ‘B(3)’. To properly depict the regression plane, you need to plot it:
Wav = linspace(min(Waist), max(Waist),25);
Wev = linspace(min(Weight), max(Weight),25);
BFv = linspace(min(BF_Pct), max(BF_Pct),25);
[Wam,Wem] = meshgrid(Wav, Wev);
Fit_Plane = B(1).*ones(size(Wam)) + B(2).*Wav + B(3).*Wev;
figure(2)
mesh(Wav(:), Wev(:), Fit_Plane)
hold on
stem3(Waist(:), Weight(:), BF_Pct(:), 'bp', 'filled')
hold off
grid on
xlabel('Waist')
ylabel('Weight')
zlabel('Body Fat %')
view([-25 25])
legend('Regression Plane', 'Data')
The relationship between waist size, height, and body fat percentage is nonlinear (and currently controversial, since such derived measures as ‘Body Mass Index’, dating from the 1830s take too few variables into account and so may not be as helpful as originally envisioned). Don’t be discouraged if the fit doesn’t look as good as you might want it to.
(Unknown)
(Unknown) 2017 年 2 月 11 日
Perfect, Thank you so much Star Strider!! :)
Star Strider
Star Strider 2017 年 2 月 11 日
My pleasure!
If it helped you, please add a Vote for it!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLinearization についてさらに検索

質問済み:

2017 年 2 月 11 日

コメント済み:

2017 年 2 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by