Issue
I've got strange (from my point of view) result from numpy polyfit
. My code:
import numpy as np
data=np.array([2482.9, 2483.0, 2485.9, 2486.0, 2486.4, 2485.1, 2485.4, 2484.9, 2484.8, 2484.8, 2484.8, 2484.0, 2484.1, 2484.1, 2484.1])
wr = range(len(data))
poly = np.polyfit(wr , data, deg = 2)
wp = np.poly1d(poly)
el = 2484.1
res = wp(el)
print(res)
#result -225256.888955
Is this a bug?
Solution
As @DSM has already said - it doesn't look like a quadratic polynom.
We can try to fit it with a higher degree though:
import numpy.polynomial.polynomial as poly
x = wr; y = data
coefs = poly.polyfit(x, y, 4)
ffit = poly.Polynomial(coefs)
plt.plot(x, y)
plt.plot(x, ffit(x))
plt.legend(['y(x)','ffit(x)'])
Result:
Answered By - MaxU - stand with Ukraine
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.