Non-linear regression
5 次查看(过去 30 天)
显示 更早的评论
I have come across the documentations for regression but am a little confused. I wanted to obtain a non-linear regression model using the following: 'sea', 'sst' and 'at'. (See files attached). I wanted to check how sst and at affect sea levels. (something similar like: 'sea' = 'sst' + 'at')
I came across this sample code:
load carbig
tbl = table(Horsepower,Weight,MPG);
modelfun = @(b,x)b(1) + b(2)*x(:,1).^b(3) + ...
b(4)*x(:,2).^b(5);
beta0 = [-50 500 -1 500 -1];
mdl = fitnlm(tbl,modelfun,beta0)
However, when I tried it on my data, I got a bad result. I would be grateful if someone could help me obtain the non-lin reg model for my data. If possible, could you send me the code too.
Thanks!
5 个评论
回答(1 个)
Image Analyst
2018-10-8
I think you're being overly optimistic if you think that data can be modeled -- predicted by some analytical function.
data = readtable('ban1.csv')
years = data.year;
sea = data.sea;
sst = data.sst;
at = data.at;
subplot(2, 2, 1);
plot(years, sea, 'b-', 'LineWidth', 2);
grid on;
title('sea vs. year', 'FontSize', 20);
xlabel('Year', 'FontSize', 20);
ylabel('sea', 'FontSize', 20);
subplot(2, 2, 2);
plot(years, sst, 'b-', 'LineWidth', 2);
xlabel('Year', 'FontSize', 20);
grid on;
hold on;
plot(years, at, 'r-', 'LineWidth', 2);
grid on;
title('sst and at vs. year', 'FontSize', 20);
legend('sst', 'at', 'location', 'west');
subplot(2, 2, 3)
scatter(sst, sea, 'filled');
grid on;
title('sea vs. sst', 'FontSize', 20);
xlabel('sea', 'FontSize', 20);
ylabel('sst', 'FontSize', 20);
subplot(2, 2, 4)
scatter(sst, at, 'filled');
grid on;
title('at vs. sst', 'FontSize', 20);
xlabel('sea', 'FontSize', 20);
ylabel('at', 'FontSize', 20);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!