Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas extrapolation of polynomial

Interpolating is easy in pandas using df.interpolate() is there a method in pandas that with the same elegance do something like extrapolate. I know my extrapolation is fitted to a second degree polynom.

like image 889
DeanLa Avatar asked Sep 17 '15 15:09

DeanLa


1 Answers

"With the same elegance" is a somewhat tall order but this can be done. As far as I'm aware you'll need to compute the extrapolated values manually. Note it is very unlikely these values will be very meaningful unless the data you are operating on actually obey a law of the form of the interpolant.

For example, since you requested a second degree polynomial fit:

import numpy as np
t = df["time"]
dat = df["data"]
p = np.poly1d(np.polyfit(t,data,2))

Now p(t) is the value of the best-fit polynomial at time t.

like image 99
AGML Avatar answered Oct 02 '22 21:10

AGML