我在pythonywhere(Python 2.7)上有一个Flask应用程序,它需要加载一个pickle文件,其中包含用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,但总是会遇到一些错误,而这个错误是最接近成功的。如果有人曾经制作过一个Flask API,它在pickle文件中使用sklearn估计器,请提供帮助。
看起来您使用的是不同版本的sklearn。I.e你用来制作模型的sklearn版本与安装在机器上用来拆开模型的版本不同。
我有一个确切的问题:我的本地机器正在使用sklearn 0.18(dev)训练和酸洗随机森林;我有一个运行sklearn 0.17的ec2实例(我从未拾取的随机林中输出预测);
>
>> 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)