“TypeError: __cinit__() 正好需要 8 个位置参数(给定 3 个)";加载 sklearn Pickle 时 [英] "TypeError: __cinit__() takes exactly 8 positional arguments (3 given)" when loading sklearn Pickle

查看:166
本文介绍了“TypeError: __cinit__() 正好需要 8 个位置参数(给定 3 个)";加载 sklearn Pickle 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 pythonanywhere (Python 2.7) 上有一个 Flask 应用程序,它需要加载一个包含用 sklearn 制作的机器学习估算器的 pickle 文件.

I have a Flask app on pythonanywhere (Python 2.7) that needs to load a pickle file containing a machine learning estimator made with sklearn.

    with open("pickle.pkl", 'rb') as f:
    d = pickle.load(f)

给我这个错误:

2016-01-06 01:20:15,469 :Exception on / [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/znagler/mysite/flask_app.py", line 29, in index
    d = pickle.load(f)
  File "/usr/lib/python2.7/pickle.py", line 1378, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 1133, in load_reduce
    value = func(*args)
  File "_tree.pyx", line 1282, in sklearn.tree._tree.Tree.__cinit__ (sklearn/tree/_tree.c:10342)
TypeError: __cinit__() takes exactly 8 positional arguments (3 given)positional arguments (3 given)

我曾尝试使用 joblib 和其他版本的 Python,但我总是遇到一些错误,而这个错误最接近成功.如果有人制作过在pickle 文件中使用sklearn 估计器的Flask API,将不胜感激.

I've tried using joblib and other versions of Python but I always get some error, and this error to be the closest to success. If anyone has ever made a Flask API that uses an sklearn estimator in a pickle file, would be grateful for assistance.

推荐答案

看来您正在使用不同版本的 sklearn.即您用来制作模型的 sklearn 版本与用于解开模型的机器上安装的版本不同.

It looks like you are using different versions of sklearn. I.e the version of sklearn that you used to make the model is not the same version installed on the machine that is used to unpickle the model.

我遇到了这个确切的问题:我的本地机器正在使用 sklearn 0.18 (dev) 训练和酸洗随机森林;我有一个运行 sklearn 0.17 的 ec2 实例(我在其中输出来自 unpickled 随机森林的预测);

I had this exact problem: my local machine was training and pickling random forests using sklearn 0.18 (dev); I had an ec2 instance running sklearn 0.17 (where I was outputting predictions from the unpickled random forest);

>

>> foo_predictor = pickle.load(open('rF_REVENUENext_version2.pkl', 'rb'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/pickle.py", line 1378, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 1133, in load_reduce
    value = func(*args)
  File "_tree.pyx", line 1282, in sklearn.tree._tree.Tree.__cinit__ (sklearn/tree/_tree.c:10342)
TypeError: __cinit__() takes exactly 8 positional arguments (3 given)

这篇关于“TypeError: __cinit__() 正好需要 8 个位置参数(给定 3 个)";加载 sklearn Pickle 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆