在Google Colab中使用NeuralProphet拟合模型时遇TypeError求助
解决NeuralProphet拟合时的TypeError问题
我运行以下代码时触发了TypeError,官方教程笔记本里也出现了同样问题:
from neuralprophet import NeuralProphet m = NeuralProphet() metrics = m.fit(df)
报错信息:
TypeError Traceback (most recent call last) <ipython-input-8-80f152464e03> in <module> 8 ar_reg=0.1, 9 ) ---> 10 metrics = m.fit(df) 6 frames /usr/local/lib/python3.7/dist-packages/neuralprophet/df_utils.py in get_normalization_params(array, norm_type) 340 if norm_type == "soft": 341 lowest = np.min(non_nan_array) ---> 342 q95 = np.quantile(non_nan_array, 0.95, method="higher") 343 width = q95 - lowest 344 if math.isclose(width, 0): <__array_function__ internals> in quantile(*args, **kwargs) TypeError: _quantile_dispatcher() got an unexpected keyword argument 'method'
解决方案
- 升级numpy版本
这个错误的核心原因是你的numpy版本过低,method="higher"参数是numpy 1.22及以上版本才引入的,旧版本numpy的np.quantile函数用的是interpolation参数而非method。执行以下命令升级numpy:
pip install --upgrade numpy
- 修改NeuralProphet源码(仅当无法升级numpy时使用)
如果因为环境限制不能升级numpy,可以找到neuralprophet/df_utils.py文件,定位到第342行,把:
q95 = np.quantile(non_nan_array, 0.95, method="higher")
替换为:
q95 = np.quantile(non_nan_array, 0.95, interpolation="higher")
这样就能兼容旧版本numpy的参数要求。
内容的提问来源于stack exchange,提问作者Gozdi
相关产品推荐
相关产品推荐

