Automatic Best Curve Fitting

36 vues (au cours des 30 derniers jours)
Swathi
Swathi le 22 Août 2012
I want to fit the best curve to my data. Everytime I have to do a trial and error method to see what fits (i.e it could be any degree of polynomial). Is there any automatic way to do this as I need to do on 100s of data set individually?
Thanks!!

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Août 2012
polyfit() your data, specifying a degree equal to (the length of the data, minus 1). Algebraically the result should be an exact fit, but unfortunately round-off error will be a significant problem for you.
If you want the best fit, there is no point using a lower degree. You do want the result to be noise-for-noise exact, right?
  5 commentaires
Image Analyst
Image Analyst le 23 Août 2012
Um, Swathi, I take it from your response that you've never taken a course in linear algebra, numerical methods, numerical analysis or whatever it's called at your university? And so you don't realize what would happen if you followed Walter's tongue in cheek advice. So, I think this would be an excellent learning experience for you. Just keep increasing the order of your polynomial and plot it and see what happens. Make sure you interpolate some points in between your training points, and outside your training range to see what happens to the estimated values there. You might also want to look up this: http://en.wikipedia.org/wiki/Lagrange_interpolation
Swathi
Swathi le 23 Août 2012
Thank you Walter and Image Analyst... I am working with curve fitting stuff for the first time.. Your suggestions and comments really help. Thanks again!!

Connectez-vous pour commenter.

Plus de réponses (2)

Star Strider
Star Strider le 23 Août 2012
Modifié(e) : Star Strider le 23 Août 2012
How do you define ‘best curve’? If you’re doing it from a statistical perspective, look in the polyfit documentation for information on calculating the covariance matrix and the 95% confidence intervals on the parameters. As a general rule, the confidence interval for a particular parameter that include zero means that parameter is not necessary in the model. So the ‘best’ polynomial models are those with all parameter confidence intervals in the model not including zero, meaning that all parameters are significantly different than zero. That could be a polynomial of a much lower degree than length(data)-1. It may not fit as well but it will at least have statistical validity, if that is a consideration.
  1 commentaire
Swathi
Swathi le 23 Août 2012
Thank you so much.. Your comments really help. I want to make sure that statistically fit is good. So thanks for the suggestion.

Connectez-vous pour commenter.


Greg Heath
Greg Heath le 23 Août 2012
It is not clear whether you want
1. To fit the sampled data containing noise and measurement error as closely as possible
or
2. To fit a larger population of data containing noise and measurement error from which the sampled data is considered to be representative.
For example, consider a sample of N = 20 points from a contaminated linear model
y = a*x + b + c*randn(1,N).
The sample data can be represented exactly by a 19th order polynomial with Np = 20 estimated coefficients. However, that polynomial is usually not a good represenative model for the population.
In the latter case functions like STEPWISE and STEPWISEFIT that can automatically choose a more reasonable polynomial order are more appropriate.
Regardless of the model, it is usually wise to use as few estimated parameters, Np, as possible to increase the confidence in the parameter estimates (Search Occam's Razor). A useful rule of thumb is to assume N > Np is necessary and N >> Np is sufficient.
In the case of nonlinear neural network models, trial and error is a relatively straightforward approach. However, more advanced techniques like regularization and validation set stopping tend to be used by frequent practicioners.
Hope this helps.
Greg
  2 commentaires
Swathi
Swathi le 23 Août 2012
Thanks Greg. I will be fitting sample by sample first and then go for the whole population. I will look into the stepwise and stepwisefit option.
Thanks again!!
Greg Heath
Greg Heath le 26 Août 2012
My point is if the sample is sufficient, the model will work on the entire population without further adjustments.
Hope this helps.
Greg

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by