Polyfit is returning coefficients from low to high instead of high to low.
See original GitHub issueDocs say that np.polyfit returns:
Polynomial coefficients, highest power first. If y was 2-D, the coefficients for k-th data set are in p[:,k].
However, at least for the linear case, it is actually returning coefficients lowest power first. Thus, for a fit y=mx+b, polyfit returns (b,m) and not (m,b) as the docs indicate.
y=np.linspace(0,10,10)
x=y
plt.plot(x,y)
m,b=polyfit(x,y,1) #Returns highest power first
print 'm is', m, 'b is', b
Output gives:
m is 0.0 b is 1.0
See that it’s reversed?
Issue Analytics
- State:
- Created 11 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Polynomial curve fitting - MATLAB polyfit - MathWorks
This MATLAB function returns the coefficients for a polynomial p(x) of degree n that is a best fit (in a least-squares sense) for...
Read more >Why do numpy's polyfit and polyval expect polynomial ...
Both polyfit and polyval expect and return polynomial coefficients ordered from low to high degree. Also note that polyval expects parameters ...
Read more >numpy.polyfit — NumPy v1.24 Manual
Computes spline fits. The coefficient matrix of the coefficients p is a Vandermonde matrix. polyfit issues a RankWarning when the least-squares fit is...
Read more >Extremely poor polyfit, what am I doing wrong?
1) Once one move away from the range of data, the quality of a polyfit based extrapolation can deteriorate pretty quickly. Don't use...
Read more >Week 6 Lecture 1
Polyfit and polyval ... This function takes the coefficients of a polynomial (remember, ... Our line is too low at the edges and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There are two polyfits, are you by chance using the one in numpy.polynomial.polynomial.
Yes thanks On Mar 8, 2013 7:29 PM, “Charles Harris” notifications@github.com wrote: