: __main__ 上的属性查找 run_prophet 失败,python,parallel-processing,prophet"/>

首页 > 解决方案 > 不能腌制: __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 调用时遗漏了一些东西,任何帮助

标签: pythonparallel-processingprophet

解决方案


推荐阅读