python之使用 Facebook Prophet 同时预测多个变量
thcjp
阅读:27
2025-06-02 22:19:02
评论:0
我是 Python 和 Facebook Prophet 的新手,所以这可能很简单,但我无法在网上找到答案。
我有一个 7 列的 csv 文件。一列包含具有每日增量的日期戳 ('ds') 列,其他 6 列('y1'、'y2'、'y3' 等)包含 6 个变量,其值与日期戳对齐。
我不想创建六个不同的两列 csv 文件并运行 Prophet 六次不同的时间(一次只预测一个变量),而是想找到一种方法来一次预测所有六个变量。这是我正在尝试的:
df = pd.read.csv('example_file.csv')
cols = ['y1','y2','y3','y4','y5','y6']
results = []
for col in cols:
subdf = df[['ds', col]].dropna()
m = Prophet()
m.fit(subdf)
result = m.predict(m.make.future.dataframe(periods = 90))
results.append(result)
df.predict = pd.concat(results, axis=1)
df.predict.to_csv('example_file.csv')
当我运行它时,我收到以下错误:
ValueError: Dataframe must have columns 'ds' and 'y' with the dates and values respectively.
任何见解/帮助将不胜感激。谢谢!
请您参考如下方法:
抱歉,我想发表评论,但我还没有足够的声誉。请重命名循环中的列
subdf = subdf.rename(columns={'ds':'ds', col:'y'})
Prophet 强加了严格的条件,即输入列被命名为 ds(时间列)和 y(度量列)。
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。