腌制的FBProphet模型将在Heroku上奔跑

发布于 2025-01-24 14:22:03 字数 1276 浏览 4 评论 0原文

我没有这样的模型:

filename = f"models/{model_name}"
model = pickle.load(open(filename, 'rb'))
forecast = model.make_future_dataframe(periods=int(period), freq='MS')
forecast = model.predict(forecast)

我会收到此错误:

2022-04-28T00:12:11.900741+00:00 app[web.1]: File "/app/app.py", line 86, in create_figure_pred
2022-04-28T00:12:11.900742+00:00 app[web.1]: model = pickle.load(open(filename, 'rb'))
2022-04-28T00:12:11.900746+00:00 app[web.1]: ModuleNotFoundError: No module named 'pandas._libs.arrays'

这是一个烧瓶应用程序。

我读到,此错误的一个潜在解决方案是卸载并重新安装pandas,但是当我按下时,pandas是由需求安装的。

另一个可能的解决方案是明确导入pandas._libs._libs。

2022-04-28T00:28:20.465322+00:00 app[web.1]: File "/app/app.py", line 13, in <module>
2022-04-28T00:28:20.465322+00:00 app[web.1]: import pandas._libs.arrays
2022-04-28T00:28:20.465326+00:00 app[web.1]: ModuleNotFoundError: No module named 
'pandas._libs.arrays'

我发现 Github上的问题如果我(例如,腌菜)然后在笔记本中取消挑剔时,请遇到这个问题。一切都按预期工作。

fbProphet肯定安装在应用中。我可以将模型安装在那里,但是页面段之前就可以完成。如果这是一个小数据集或预测期,则有效。

Github上还有另一个问题,没有人回应,听起来像是一个好问题。如果我可以再次找到它,我将在这里更新。

I am unpickling the model like so:

filename = f"models/{model_name}"
model = pickle.load(open(filename, 'rb'))
forecast = model.make_future_dataframe(periods=int(period), freq='MS')
forecast = model.predict(forecast)

I get this error:

2022-04-28T00:12:11.900741+00:00 app[web.1]: File "/app/app.py", line 86, in create_figure_pred
2022-04-28T00:12:11.900742+00:00 app[web.1]: model = pickle.load(open(filename, 'rb'))
2022-04-28T00:12:11.900746+00:00 app[web.1]: ModuleNotFoundError: No module named 'pandas._libs.arrays'

It's a Flask app.

I read that one potential solution for this error is to uninstall and reinstall pandas but pandas is installed by requirements.txt when I push.

Another possible solution is to import pandas._libs.arrays explicitly but this did not work.

2022-04-28T00:28:20.465322+00:00 app[web.1]: File "/app/app.py", line 13, in <module>
2022-04-28T00:28:20.465322+00:00 app[web.1]: import pandas._libs.arrays
2022-04-28T00:28:20.465326+00:00 app[web.1]: ModuleNotFoundError: No module named 
'pandas._libs.arrays'

I found an issue on github but this isn't very helpful because I don't have this problem when if I, for example, pickle and then unpickle in a notebook. It all works as expected.

fbprophet is definitely installed in the app. I can fit the model there but the page times out before it finishes. If it's a small dataset or forecasting period, it works.

There was another issue on github that no one responded to and sounded like a good question. I'll update here if I can find it again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜访吸血鬼 2025-01-31 14:22:03

我也有同样的问题。

> python
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open( 'myFile.pkl', 'rb' ) as f:
...     df = pickle.load( f )
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ModuleNotFoundError: No module named 'pandas._libs.arrays'

看起来腌制的对象是用确实具有._libs.Arrays的Pandas的版本创建的,但是尝试泡菜的版本没有:

>>> pandas.__version__
'1.1.3'
>>> dir ( pandas._libs )
['Interval', 'NaT', 'NaTType', 'OutOfBoundsDatetime', 'Period', 'Timedelta', 'Timestamp', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'algos', 'groupby', 'hashing', 'hashtable', 'iNaT', 'index', 'indexing', 'internals', 'interval', 'join', 'json', 'lib', 'missing', 'ops', 'ops_dispatch', 'parsers', 'properties', 'reduction', 'reshape', 'sparse', 'testing', 'tslib', 'tslibs', 'window', 'writers']

升级的Pandas:

> python -m pip install pandas -U
Successfully installed pandas-1.4.3 python-dateutil-2.8.2 pytz-2022.2.1

现在看起来很高兴:

python
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open( 'myFile.pkl', 'rb' ) as f:
...     df = pickle.load( f )
... 
>>> 
>>> import pandas
>>> 'arrays' in dir( pandas._libs )
True

I had this same problem.

> python
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open( 'myFile.pkl', 'rb' ) as f:
...     df = pickle.load( f )
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ModuleNotFoundError: No module named 'pandas._libs.arrays'

Looks like the pickled object was created with a version of pandas that does have ._libs.arrays, but the version attempting pickle.load does not :

>>> pandas.__version__
'1.1.3'
>>> dir ( pandas._libs )
['Interval', 'NaT', 'NaTType', 'OutOfBoundsDatetime', 'Period', 'Timedelta', 'Timestamp', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'algos', 'groupby', 'hashing', 'hashtable', 'iNaT', 'index', 'indexing', 'internals', 'interval', 'join', 'json', 'lib', 'missing', 'ops', 'ops_dispatch', 'parsers', 'properties', 'reduction', 'reshape', 'sparse', 'testing', 'tslib', 'tslibs', 'window', 'writers']

Upgraded pandas :

> python -m pip install pandas -U
Successfully installed pandas-1.4.3 python-dateutil-2.8.2 pytz-2022.2.1

Now it seems happy:

python
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open( 'myFile.pkl', 'rb' ) as f:
...     df = pickle.load( f )
... 
>>> 
>>> import pandas
>>> 'arrays' in dir( pandas._libs )
True
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文