Regression for each category
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
Suppose I have following data: the first column is the city, the second column is the height, and the third column is weight.
Then I want to run regression of weight = height for each city.
What code should I use?
0 件のコメント
回答 (2 件)
Image Analyst
2017 年 12 月 27 日
Use == on column 1 to identify the city (if they're numbered), then (if you want a polynomial regression) use polyfit() on rows for one city, one city at a time. Attach your data if you want more help.
% Find city #3, for example
thisCity = data(:, 1) == 3; % Find if column1 = 3
% Extract heights from column 2, but only from this city.
heights = data(thisCity, 2);
% Extract weights from column 3, but only from this city.
weights = data(thisCity, 3);
% Perform a quadratic (2nd order) regression.
coefficients = polyfit(weights, heights, 2); % Or swap heights and weights if you want.
0 件のコメント
Star Strider
2017 年 12 月 27 日
0 投票
If you have the Statistics and Machine Learning Toolbox, see the examples in the documentation for the mvregress (link) function.
0 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!