先知假日发行

2024-10-03 17:27:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在Python中使用htsprophet包。我使用下面的示例代码。这个例子来自https://github.com/CollinRooney12/htsprophet/blob/master/htsprophet/runHTS.py。我得到的问题是ValueError"holidays must be a DataFrame with 'ds' and 'holiday' column。我想知道是否有一个解决这个问题的方法,因为我显然有一个数据框架,其中有两列ds和holidays。我相信这个错误来自fbprophet的一个依赖包来自forecaster文件。我想知道是否有什么我需要添加或是否有人添加了一些东西来解决这个问题。在

import pandas as pd
from htsprophet.hts import hts, orderHier, makeWeekly
from htsprophet.htsPlot import plotNode, plotChild, plotNodeComponents
import numpy as np

#%% Random data (Change this to whatever data you want)
date = pd.date_range("2015-04-02", "2017-07-17")
date = np.repeat(date, 10)
medium = ["Air", "Land", "Sea"]
businessMarket = ["Birmingham","Auburn","Evanston"]
platform = ["Stone Tablet","Car Phone"]
mediumDat = np.random.choice(medium, len(date))
busDat = np.random.choice(businessMarket, len(date))
platDat = np.random.choice(platform, len(date))
sessions = np.random.randint(1000,10000,size=(len(date),1))
data = pd.DataFrame(date, columns = ["day"])
data["medium"] = mediumDat
data["platform"] = platDat
data["businessMarket"] = busDat
data["sessions"] = sessions

#%% Run HTS
##
# Make the daily data weekly (optional)
##
data1 = makeWeekly(data)
##
# Put the data in the format to run HTS, and get the nodes input (a list of list that describes the hierarchical structure)
##
data2, nodes = orderHier(data, 1, 2, 3)
##
# load in prophet inputs (Running HTS runs prophet, so all inputs should be gathered beforehand)
# Made up holiday data
##
holidates = pd.date_range("12/25/2013","12/31/2017", freq = 'A')
holidays = pd.DataFrame(["Christmas"]*5, columns = ["holiday"])
holidays["ds"] = holidates
holidays["lower_window"] = [-4]*5
holidays["upper_window"] = [0]*5
##
# Run hts with the CVselect function (this decides which hierarchical aggregation method to use based on minimum mean Mean Absolute Scaled Error)
# h (which is 12 here) - how many steps ahead you would like to forecast.  If youre using daily data you don't have to specify freq.
#
# NOTE: CVselect takes a while, so if you want results in minutes instead of half-hours pick a different method
##
myDict = hts(data2, 52, nodes, holidays = holidays, method = "FP", transform = "BoxCox")
##

Tags: thetoimportyoudataframedatadatelen
1条回答
网友
1楼 · 发布于 2024-10-03 17:27:07

问题出在htsProphet包中,带有'菲特预测.py'文件。fbProphet对象的实例化仅依赖于位置参数,但是在fbProphet类中添加了一个新参数。这意味着论点不再一致。在

您可以通过破解fbProphet模块并将位置参数更改为关键字参数来解决此问题,只需修复“73-74”行就足以使其运行:

Prophet(growth=growth, changepoints=changepoints1, n_changepoints=n_changepoints1, yearly_seasonality=yearly_seasonality, weekly_seasonality=weekly_seasonality, holidays=holidays, seasonality_prior_scale=seasonality_prior_scale, \
                            holidays_prior_scale=holidays_prior_scale, changepoint_prior_scale=changepoint_prior_scale, mcmc_samples=mcmc_samples, interval_width=interval_width, uncertainty_samples=uncertainty_samples)

我会为此向创造者提交一个bug。在

相关问题 更多 >