Automatic Best Curve Fitting
조회 수: 6 (최근 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!