多项式的 pandas 外推 [英] pandas extrapolation of polynomial

查看:57
本文介绍了多项式的 pandas 外推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用df.interpolate()在熊猫中插值很容易 在大熊猫中,有没有一种方法可以像优雅一样做类似推断的事情.我知道我的推论适合二阶多项式.

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.

推荐答案

具有相同的优雅度"虽然有点高,但是可以做到.据我所知,您将需要手动计算外推值.请注意,除非您所操作的数据实际上服从插值形式的定律,否则这些值不太可能有意义.

"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))

现在p(t)是时刻t的最佳拟合多项式的值.

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

这篇关于多项式的 pandas 外推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆