Automatic Best Curve Fitting
7 次查看(过去 30 天)
显示 更早的评论
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!!
0 个评论
采纳的回答
Walter Roberson
2012-8-22
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 个评论
Image Analyst
2012-8-23
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
更多回答(2 个)
Star Strider
2012-8-23
编辑:Star Strider
2012-8-23
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.
Greg Heath
2012-8-23
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 个评论
Greg Heath
2012-8-26
My point is if the sample is sufficient, the model will work on the entire population without further adjustments.
Hope this helps.
Greg
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!