pandas - Facebook-Prophet 每月数据交叉验证 - 解决方法 : Pandas timedelta does not support Month and Years

标签 pandas cross-validation timedelta facebook-prophet

我正在使用 Facebook Prophet 按月预测一些时间序列数据。

ds           y  
2020-02-01  400.0
2020-03-01  450.0
2020-04-01  0.0 
2020-05-01  225.0

我想使用 cross_validation() 函数来评估我的结果。

from fbprophet.diagnostics import cross_validation,performance_metrics
cv_results = cross_validation(
   model = m,
   initial = pd.to_timedelta(12,unit="M"), 
   horizon = pd.to_timedelta(12,unit="M"))
df_p = performance_metrics(cv_results)

但是我收到以下消息: ValueError:不再支持单位“M”和“Y”,因为它们不表示明确的时间增量值持续时间。

有人有解决方法吗?谢谢!

最佳答案

我认为 pandas 不再支持超过一天(“D”)的单位。 每当您对这些时间单位使用 pandas timedelta 时,就会出现此问题。

我建议使用天数并将 30 天乘以预期的月数

from fbprophet.diagnostics import cross_validation,performance_metrics

cv_results = cross_validation(
   model = m,
   initial = pd.to_timedelta(30*12,unit="D"), 
   horizon = pd.to_timedelta(30*12,unit="D"))
df_p = performance_metrics(cv_results)```

关于pandas - Facebook-Prophet 每月数据交叉验证 - 解决方法 : Pandas timedelta does not support Month and Years,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65197392/

相关文章:

machine-learning - 我是否使用训练集中的相同 idf 来执行交叉验证?

python - LightGBM 中的交叉验证

pyinstaller 导入错误 : C extension: No module named np_datetime not built

python - 如何正确地将时间索引格式 HH :MM:SS. fs 导入并绘制到 Pandas 数据框中

python - 根据Python中的日期提取和 reshape 数据

python - 基于列标准的 Panda Dataframe 重采样

python - Pandas 创建新的日期行和正向填充列值

python - Pandas 。选择多列中有缺失值的行

scala - 如何在 spark-ml CrossValidatorModel 中获得最佳逻辑回归的系数?

python - 了解时间增量