'Fitting using Chebyshev polynomials in python
I am trying to fit 2d data using polynomial fit and find that after a certain degree of polynomials, numpy gives "Rank Warning". On the other hand, fitting using Chebyshev polynomials do not give such warnings. I could able to fit the same data using Chebyshev of numpy. The output is in the form of Chebyshev polynomials of different ranks.
I want to calculate numerical value of these Chebyshev polnomials so that I can compare the results with normal polynomial fitting. Here is the sample code.
import numpy as np
from numpy.polynomial import Chebyshev as T
import os
from mpmath import *
mp.dps = 16
mp.pretty = True
x = [1, 2, 3, 4, 5]
y = [0.90, 8.15, 26.84, 64.87, 124.0]
deg = 3
popt_poly = np.polyfit(x, y, deg)
popt_cheb = T.fit(x, y, deg)
ypred = np.polyval(popt_poly, x)
print(popt_poly)
print(ypred)
print(popt_cheb)
Thanking you in advance.
Solution 1:[1]
Please use "window=" parameter. In this case: window=[1,5]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | AnatolyT |