import numpy as np
import matplotlib.pyplot as plt
from numpy.polynomial import Chebyshev as T
X=np.array([1,2,4,5,6,7,8,9,10,11,12,13])
data=np.array([2.312,4.563,6.765,7.897,12.456,7.568,6.543,3.453,6.654,9.678,11.453,19.567])
p=T.fit(X,data,6)
plt.plot(X,data)
plt.plot(*p.linspace(60))
I generated a data for which i am doing fitting using numpy polynomial chebyshev. the chebyshev is fitting the data but i dont know how am i going to get the the fitted data values from this code? Is there any way to get the fitted values or do i have to change the whole code?
At the end of your code, the Chebyshev
data structure p
holds what is needed to get any fitted value. For example, the expression
list(zip(*p.linspace(60)))
gives a list of 60 points, where each x
coordinate is a value betwee 1
and 13
, which were the bounds you gave for x
values. The corresponding y
value is the fitted value for the x
value. You can then just choose which of the points you want.
Here is the result for that expression after running your code:
[(1.0, 2.541204853676799),
(1.2033898305084745, 2.808340815346975),
(1.4067796610169492, 3.0743429556868413),
(1.6101694915254239, 3.348688496878723),
(1.8135593220338984, 3.637978305373278),
(2.016949152542373, 3.9462679999194794),
(2.2203389830508478, 4.27538454719654),
(2.4237288135593222, 4.625228345047772),
(2.6271186440677967, 4.994060793316362),
(2.830508474576271, 5.3787773522831195),
(3.0338983050847457, 5.775166088706113),
(3.2372881355932206, 6.178151709462269),
(3.440677966101695, 6.582025082790894),
(3.6440677966101696, 6.980658247139146),
(3.8474576271186445, 7.367704907609403),
(4.050847457627119, 7.736786420008617),
(4.254237288135593, 8.081663262499552),
(4.4576271186440675, 8.396391994853994),
(4.661016949152542, 8.675467705307872),
(4.864406779661017, 8.913951945018319),
(5.067796610169491, 9.107586150122668),
(5.271186440677966, 9.252890551399389),
(5.474576271186441, 9.347248571530947),
(5.677966101694915, 9.388976709968594),
(5.88135593220339, 9.37737991539911),
(6.084745762711865, 9.312792445813466),
(6.288135593220339, 9.196604216177416),
(6.491525423728814, 9.031272633704036),
(6.694915254237289, 8.820319920728197),
(6.898305084745763, 8.568315925182945),
(7.101694915254238, 8.280846418677859),
(7.305084745762712, 7.964466882179304),
(7.508474576271187, 7.626641779292636),
(7.711864406779662, 7.275669317146346),
(7.915254237288136, 6.920591694878116),
(8.11864406779661, 6.5710908397228325),
(8.322033898305085, 6.237369630702523),
(8.52542372881356, 5.930018609918223),
(8.728813559322035, 5.6598681814437874),
(8.932203389830509, 5.437826297821619),
(9.135593220338983, 5.274701634160355),
(9.338983050847459, 5.1810122498344615),
(9.542372881355933, 5.166779737785785),
(9.745762711864407, 5.241308861427015),
(9.949152542372882, 5.412952679147101),
(10.152542372881356, 5.68886315641859),
(10.35593220338983, 6.074727265506907),
(10.559322033898306, 6.574488572781565),
(10.76271186440678, 7.190054313629292),
(10.966101694915254, 7.920987954969137),
(11.16949152542373, 8.764187245369472),
(11.372881355932204, 9.713547752766893),
(11.576271186440678, 10.75961188978718),
(11.779661016949154, 11.889203426668058),
(11.983050847457628, 13.08504749178393),
(12.186440677966102, 14.325376059772596),
(12.389830508474578, 15.583518927263885),
(12.593220338983052, 16.827480176210102),
(12.796610169491526, 18.019500124818624),
(13.0, 19.115602766086262)]