python - 不能腌制: __main__ 上的属性查找 run_prophet 失败
问题描述
我正在尝试使用先知算法进行预测。由于我的数据有多个类别,试图实现并行处理。获取无法腌制 <function run_prophet at 0x7faeb26e6320>:调用函数时main上的属性查找 run_prophet 失败。
如果我删除并行处理,并只使用地图调用,它工作正常。
import numpy as np
import multiprocessing as mp
import multiprocessing.util as util
from tqdm import tqdm
def rnd_timeserie(min_date, max_date):
time_index = pd.date_range(min_date, max_date)
dates = (pd.DataFrame({'ds': pd.to_datetime(time_index.values)},
index=range(len(time_index))))
y = np.random.random_sample(len(dates))*10
dates['y'] = y
return dates
series = [rnd_timeserie('2018-01-01','2018-12-30') for x in range(0,5)]
def run_prophet(timeserie):
model = Prophet(yearly_seasonality=False,daily_seasonality=False)
model.fit(timeserie)
forecast = model.make_future_dataframe(periods=90, include_history=False)
forecast = model.predict(forecast)
return forecast
p=mp.Pool(2)
result=list(tqdm(p.imap(run_prophet,series)))
p.close()
p.join()
PicklingError: Can't pickle <function run_prophet at 0x7faeb26e6320>: attribute lookup run_prophet on __main__ failed
我对 python 很陌生,如果我在使用 p.imap 调用时遗漏了一些东西,任何帮助
解决方案
推荐阅读
- flask - Flask-SQLAlchemy wont create tables and Foreign Key
- java - JDA反应事件监听器java
- sas - using the <> operator for not equal to in sas with text
- android - Split strings on string array
- c# - 以编程方式在单元格中居中文本:适用于单行文本,但不适用于更长的时间
- python-3.x - Python ModuleNotFoundError:没有名为“win32event”的模块
- maven - 如何在声纳中创建子项目
- qt - 如何直接访问 Qt qrc 文件夹 Qt 5.10.1
- java - 路由器池中的 context().parent()
- python - 将操作和列表应用于嵌套列表