Scatter Plot Curve Fitting!!

4 views (last 30 days)
Selen
Selen on 27 May 2014
Commented: Star Strider on 27 May 2014
Hi,
I am trying to find a curve that goes through the scatter plot below. It would be great if the curve can minimize the error. There is no polynomial order or fittype restriction.
Thanks!

Answers (1)

Star Strider
Star Strider on 27 May 2014
In such an unrestricted situation, simply use polyfit and its friends polyval and others (all linked to at the end of the page).
I suggest you start with a line (degree 1) and increase the order of the polynomial fit to get one that makes sense to you but does not ‘overfit’ your data.
If you want to minimise the error, calculate the sum-of-squares of the residuals with each increase in order. (You can actually put this in a loop if you like.) When they’re small enough and you’re happy with the way it looks, stop. Something less than a 5th degree polynomial will likely be optimal.
  2 Comments
John D'Errico
John D'Errico on 27 May 2014
Be careful here. It is easy to overfit a polynomial model, using too high of a degree. In this case, you have 11 unique data points, so a 10th degree polynomial is theoretically the highest order curve you could fit to it and get something rational out if it. However, even there you will find that is too high of a degree in general. Such a curve fit will probably do wild and wooly things between the points.
You can also use my SLM toolbox (found on the file exchange) for a fit. It is designed to incorporate your knowledge of the process into the curve fit.
Star Strider
Star Strider on 27 May 2014
Agreed.
That’s the reason I suggested stopping at half that, or 5.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!