How to include a maximum error constraint of e.g. 10% when using polyfit?
3 ビュー (過去 30 日間)
古いコメントを表示
Hi guys,
I am interested to include a pre-defined max error of let's say 10% when using polyfit in my data. More specifically, I am interested to start from the left corner of my X and Y data, and find the earliest sample point (closer to the left corner) that satisfies a constrain of <10% error between my polyfit and my data.
I guess there may be ways to assess the fit on a step by step mode, and then isolate which part of the curve first satisfies this constraint, but I believe there will be a more efficient and concise way to do so.
I am attaching some of my X and Y data for your convenience.
Any ideas?
Thank you,
George
7 件のコメント
John D'Errico
2019 年 4 月 26 日
I might try to answer this question, but I have no idea what you intend here.
You can compute the error of a particular point. That is just
err(i) = y(i) - ypred(i)
percent error? Also trivial.
perc_err(i) = 100*(y(i) - ypred(i))/y(i);
So percent error is a relative thing. Note that polyfit is NOT designed to produce a relative error fit.
But again, each of those things are an error for a particular point. To talk about the percent error for the polynomial itself seems to have no meaning that I can think of. You may know what you want, but making up some jargon that makes sense only to you will not get a useful answer. You need to CLEARLY explain what you are trying to do. Again, remember that polyfit is NOT designed to work in terms of a relative error metric. So the fit that polyfit does produce will probably not be targeted at your goal.
You then ask about wanting to find a fit that maintains some goal % error over some region of the curve. Again, polyfit is not designed to essentially truncate the data until some goal on the fit is reached. Before you even try to do such a fit though, you need to define what this percent error should mean.
Walter Roberson
2019 年 4 月 26 日
I think it could make sense to talk about max(abs(perc_err)) being 10 (%).
I am wondering if the question is along the lines of:
polydegree = 6; %for example
numpoint = length(X);
found = false;
for idx = polydegree : numpoint
[p, s] = polyfit(X(1:idx), Y(1:idx));
ypred = polyval(p, X, s);
rel_err = abs((Y - ypred)./Y);
if max(rel_err) <= 0.10
found = true;
break
end
end
if ~found
fprintf('Your polynomial cannot be fit to within 10% using degree %d\n', polydegree);
else
fprintf('Success at point #%d\n', idx);
end
... but I have the sneaking suspicion that the they want to keep increasing the degree...
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Classification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!