fit data with a line
3 次查看(过去 30 天)
显示 更早的评论
ok
回答(1 个)
Ameer Hamza
2020-6-19
Try something like this
x = linspace(0, 1, 100);
y = 3*x + 2 + rand(size(x));
pf = polyfit(x, y, 1);
y_pred = polyval(pf, x);
r2 = rsquare(y, y_pred); % R-squared
sse = sum((y-y_pred).^2); % SSE
2 个评论
Ameer Hamza
2020-6-19
Oh! I forgot to mention, rsquare is from this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/34492-r-square-the-coefficient-of-determination
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!