June 2015
Beginner
348 pages
8h 44m
English
The NumPy polyfit() function fits a set of data points to a polynomial, even if the underlying function is not continuous:
bhp=np.loadtxt('BHP.csv', delimiter=',', usecols=(6,), unpack=True)
vale=np.loadtxt('VALE.csv', delimiter=',', usecols=(6,), unpack=True)
t = np.arange(len(bhp))
poly = np.polyfit(t, bhp - vale, 3)
print("Polynomial fit", poly)The polynomial fit (in this example, a cubic polynomial was chosen) is as follows:
Polynomial fit [ 1.11655581e-03 -5.28581762e-02 5.80684638e-01 5.79791202e+01]
Read now
Unlock full access