【问题标题】:Extrapolate using interp2d from scipy python使用来自 scipy python 的 interp2d 进行推断
【发布时间】:2016-09-21 20:46:52
【问题描述】:

我正在尝试使用 scipy 包进行 2d 推断,例如:

interp2d(df['maturity'], df['strike'], df['IV'], fill_value='extrapolate')(0.08, 0.65)

df['maturity'] 的最小值是 0.09,我得到以下错误:

    IV = interp2d(group['maturity'], group['strike'], group['IV'], fill_value='extrapolate')(0.08, 0.65)
  File "C:\Anaconda2\lib\site-packages\scipy\interpolate\interpolate.py", line 298, in __call__
    z[:, out_of_bounds_x] = self.fill_value
ValueError: could not convert string to float: extrapolate

fill_value='extrapolate' 在 interp1d 上完美运行...知道是否有一种简单的方法可以在 2d 方法上进行推断?

谢谢。

【问题讨论】:

  • 它在抱怨字符串值,那么这里的 dtype 是什么? df.info() 显示什么?
  • code <class 'pandas.core.frame.DataFrame'> date 72 non-null datetime64[ns] IV 72 non-null float64 maturity 72 non-null float64 strike 72 non-null float64 问题似乎来自它使用 z[:, out_of_bounds_x] = self.fill_value 并尝试以某种方式传递字符串的事实。事实上,我认为它尝试像这样传递两个值 :(0.08, 0.65) 并看到它有一个字符串

标签: python python-2.7 pandas scipy


【解决方案1】:

看来我没有做家庭作业。

fill_value = 'extrapolate'

仅适用于 interp1d。如果你不给 interp2d 一个 fill_value 参数,它会外推。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 1970-01-01
    • 2011-03-02
    相关资源
    最近更新 更多