我的数据集中有大约 23300 个每小时数据点,我尝试使用 Facebook Prophet 进行预测。要微调超参数,可以使用交叉验证:
from fbprophet.diagnostics import cross_validation
Run Code Online (Sandbox Code Playgroud)
整个过程如下所示: https: //facebook.github.io/prophet/docs/diagnostics.html
使用cross_validation1 需要指定initial,period和horizon:
df_cv = cross_validation(m, initial='xxx', period='xxx', horizon = 'xxx')
Run Code Online (Sandbox Code Playgroud)
我现在想知道如何在我的情况下配置这三个值?如前所述,我拥有大约 23.300 个每小时数据点的数据。我应该将其中的一小部分作为范围,还是将数据的正确部分作为范围并不那么重要,并且我可以采用任何看起来合适的值?
此外,cutoffs还定义如下:
cutoffs = pd.to_datetime(['2013-02-15', '2013-08-15', '2014-02-15'])
df_cv2 = cross_validation(m, cutoffs=cutoffs, horizon='365 days')
Run Code Online (Sandbox Code Playgroud)
这些是否cutoffs应该像上面一样平均分配,或者我们可以cutoffs按照某人喜欢的方式单独设置它们吗?
尝试安装 fbprophet 时,安装卡在这部分
为收集的包构建轮子:先知 为先知构建轮子(setup.py)... | pystan 和 ehem 已安装。操作系统ubuntu 20.04
我在 Jupyter Notebook 上使用 fbprophet 版本 0.7.1 和 pystan 2.19.1.1 处理季度时间序列数据。
使用额外的回归器,这是我的代码。
model = Prophet(daily_seasonality = False, weekly_seasonality = False)
for regressor in extra_regressors:
model.add_regressor(regressor)
model.fit(df_train)
Run Code Online (Sandbox Code Playgroud)
这会导致非常长的日志/输出,例如:
Initial log joint probability = -50.7823
Iteration 1. Log joint probability = 36.5594. Improved by 87.3417.
Iteration 2. Log joint probability = 47.9345. Improved by 11.3751.
Iteration 3. Log joint probability = 61.4267. Improved by 13.4922.
Iteration 4. Log joint probability = 70.6681. Improved by 9.24134.
Iteration 5. Log joint probability = 73.2246. …Run Code Online (Sandbox Code Playgroud) 我对在 Python 和 Prophet 中做时间序列很陌生。我有一个包含变量文章代码、日期和销售数量的数据集。我正在尝试使用 Python 中的 Prophet 预测每个月每篇文章的销售数量。
我尝试使用 for 循环对每篇文章进行预测,但我不确定如何在输出(预测)数据中显示文章类型,并将其直接从“for 循环”写入文件。
df2 = df2.rename(columns={'Date of the document': 'ds','Quantity sold': 'y'})
for article in df2['Article bar code']:
# set the uncertainty interval to 95% (the Prophet default is 80%)
my_model = Prophet(weekly_seasonality= True, daily_seasonality=True,seasonality_prior_scale=1.0)
my_model.fit(df2)
future_dates = my_model.make_future_dataframe(periods=6, freq='MS')
forecast = my_model.predict(future_dates)
return forecast
Run Code Online (Sandbox Code Playgroud)
我想要如下输出,并希望将其直接从“for 循环”写入输出文件。
提前致谢。
有人能解释一下如何在 Python3 上安装 Prophet 吗?
我试过了,pip install fbprophet但没有用。
在导入 pandas 和 sklearn 后尝试在笔记本中执行此操作并出现另一个错误:
import pandas as pd
import sklearn as sk
from fbprophet import Prophet
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-f503e9c6cf11> in <module>()
----> 1 from fbprophet import Prophet
ModuleNotFoundError: No module named 'fbprophet'
Run Code Online (Sandbox Code Playgroud) 我对在 R 中使用 Prophet 进行时间序列预测非常陌生。我能够使用 Prophet 预测单个产品的值。如果我可以使用循环为多个产品使用 Prophet 生成预测,有什么办法吗?下面的代码对单个产品非常有效,但我正在尝试为多个产品生成预测
library(prophet)
df <- read.csv("Prophet.csv")
df$Date<-as.Date(as.character(df$Date), format = "%d-%m-%Y")
colnames(df) <- c("ds", "y")
m <- prophet(df)
future <- make_future_dataframe(m, periods = 40)
tail(future)
forecast <- predict(m, future)
write.csv(forecast[c('ds','yhat')],"Output_Prophet.csv")
tail(forecast[c('ds', 'yhat', 'yhat_lower', 'yhat_upper')])
Run Code Online (Sandbox Code Playgroud)
样本数据集:
基本上我有 780 个(每天)观察,我想从中训练 80% 的数据,剩下的 20% 用于交叉验证。因此我明白我将使用:
df_cv = cross_validation(m, initial='624 days', horizon='156 days')
Run Code Online (Sandbox Code Playgroud)
其中初始日期对应于我想训练和观察我想用于交叉验证的剩余观察值的第一个观察值。
我想我没有正确应用它,因为它似乎是一个截止日期,我真的不明白这是为了什么。
我怎样才能实现我的目标,即使用最初的 80% 的观察来训练数据,最后 20% 进行交叉验证?
先感谢您
machine-learning prediction python-3.x cross-validation facebook-prophet
这是完整的错误消息。
Traceback (most recent call last):
File "C:\Users\adi\OneDrive\Desktop\Python310\machine learning project.py", line 3, in <module>
import streamlit as st
File "C:\Users\adi\OneDrive\Desktop\Python310\lib\site-packages\streamlit\__init__.py", line 70, in <module>
from streamlit.delta_generator import DeltaGenerator as _DeltaGenerator
File "C:\Users\adi\OneDrive\Desktop\Python310\lib\site-packages\streamlit\delta_generator.py", line 19, in <module>
from streamlit import cursor, caching
File "C:\Users\adi\OneDrive\Desktop\Python310\lib\site-packages\streamlit\cursor.py", line 18, in <module>
from streamlit.scriptrunner import get_script_run_ctx
File "C:\Users\adi\OneDrive\Desktop\Python310\lib\site-packages\streamlit\scriptrunner\__init__.py", line 16, in <module>
from .script_runner import (
File "C:\Users\adi\OneDrive\Desktop\Python310\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 35, in <module>
from streamlit.state import (
File "C:\Users\adi\OneDrive\Desktop\Python310\lib\site-packages\streamlit\state\__init__.py", line 27, in <module>
from .session_state_proxy import …Run Code Online (Sandbox Code Playgroud) 这是代码数据和在python中使用Fbprophet库时遇到的错误。
数据
Timestamp Open High Low y Volume \
0 1519084800 11379.2 11388.9 11379.2 11388.9 0.083001
1 1519084860 11362.0 11362.0 11362.0 11362.0 0.017628
2 1519084920 11383.9 11395.0 11370.7 11393.0 3.023621
3 1519084980 11384.3 11399.0 11379.9 11387.3 2.979175
4 1519085040 11395.0 11400.0 11390.1 11390.1 1.430360
ds y_orig y_pred
0 2018-02-20 00:00:00 11388.9 9.340394
1 2018-02-20 00:01:00 11362.0 9.338030
2 2018-02-20 00:02:00 11393.0 9.340754
3 2018-02-20 00:03:00 11387.3 9.340254
4 2018-02-20 00:04:00 11390.1 9.340500
Run Code Online (Sandbox Code Playgroud)
码:
model = Prophet(growth='logistic')
model.fit(data);
#create 12 months …Run Code Online (Sandbox Code Playgroud) 您好,当我尝试在 google colab 上安装 fbprophet 时,出现此错误,有人知道如何解决吗?
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting fbprophet
Using cached fbprophet-0.7.1.tar.gz (64 kB)
Requirement already satisfied: Cython>=0.22 in /usr/local/lib/python3.7/dist-packages (from fbprophet) (0.29.30)
Requirement already satisfied: cmdstanpy==0.9.5 in /usr/local/lib/python3.7/dist-packages (from fbprophet) (0.9.5)
Requirement already satisfied: pystan>=2.14 in /usr/local/lib/python3.7/dist-packages (from fbprophet) (3.3.0)
Requirement already satisfied: numpy>=1.15.4 in /usr/local/lib/python3.7/dist-packages (from fbprophet) (1.21.6)
Requirement already satisfied: pandas>=1.0.4 in /usr/local/lib/python3.7/dist-packages (from fbprophet) (1.3.5)
Requirement already satisfied: matplotlib>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from fbprophet) (3.2.2)
Requirement already satisfied: LunarCalendar>=0.0.9 in /usr/local/lib/python3.7/dist-packages (from fbprophet) …Run Code Online (Sandbox Code Playgroud) facebook-prophet ×10
python ×7
for-loop ×2
forecasting ×1
hour ×1
installation ×1
logging ×1
prediction ×1
pyarrow ×1
pystan ×1
python-2.7 ×1
python-3.x ×1
r ×1
streamlit ×1
time-series ×1
ubuntu ×1