500 error posting ClassifierChain model
When posting the following model to chantilly it generates a 500 error. I have tried this with all three "flavors" with the same result. I can successfully post other models just not this one.
model = feature_selection.VarianceThreshold(threshold=0.01) model |= preprocessing.StandardScaler() model |= multioutput.ClassifierChain( model=linear_model.LogisticRegression(), order=list(range(5)) )
from syslog:
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: [2020-04-06 18:07:48,870] ERROR in app: Exception on /api/model [POST]
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: Traceback (most recent call last):
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2446, in wsgi_app
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: response = self.full_dispatch_request()
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1951, in full_dispatch_request
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: rv = self.handle_user_exception(e)
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1820, in handle_user_exception
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: reraise(exc_type, exc_value, tb)
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 39, in reraise
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: raise value
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1949, in full_dispatch_request
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: rv = self.dispatch_request()
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1935, in dispatch_request
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: return self.view_functions[rule.endpoint](**req.view_args)
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/app/api.py", line 97, in model
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: model = dill.loads(flask.request.get_data())
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 275, in loads
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: return load(file, ignore, **kwds)
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 270, in load
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: return Unpickler(file, ignore=ignore, **kwds).load()
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 472, in load
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: obj = StockUnpickler.load(self)
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: TypeError: __init__() missing 1 required positional argument: 'model'
Apr 6 18:07:48 ip-172-26-7-45 chantilly[17628]: 127.0.0.1 - - [06/Apr/2020 18:07:48] "#033[35m#033[1mPOST /api/model HTTP/1.1#033[0m" 500 -
Thanks for opening the issue, I'll look into it.
I just tried to dill it to file and load it again and also received an error.
Traceback (most recent call last):
File "classify_sample.py", line 56, in <module>
model = dill.load(f)
File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 270, in load
return Unpickler(file, ignore=ignore, **kwds).load()
File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 472, in load
obj = StockUnpickler.load(self)
TypeError: __init__() missing 1 required positional argument: 'model'
Okay I found and fixed the bug. It's because ClassifierChain inherited from collections.OrderedDict, which isn't meant to be subclassed. It now inherits from collections.UserDict and everything works fine. I've also added a series of unit tests to make sure this never happens again.
The fix will be available in the next creme release. For the moment you can simply install the master branch, which is stable, by running pip install git+https://github.com/creme-ml/creme --upgrade.