Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to convert RandomForestClassifier to javascript #28

Closed
aflugge opened this issue Feb 15, 2018 · 3 comments
Closed

Error when trying to convert RandomForestClassifier to javascript #28

aflugge opened this issue Feb 15, 2018 · 3 comments

Comments

@aflugge
Copy link

aflugge commented Feb 15, 2018

Hi,

I am trying to run the command:
python -m sklearn_porter -i estimator.pkl --js
as instructed on the github readme, with a sklearn random forest classifier that I saved into estimator.pkl as instructed. I am using Python 3.6 from Anaconda on a Ubuntu 16.04 LTS.
But it fails with following error:
Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/user/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/user/anaconda3/lib/python3.6/site-packages/sklearn_porter/main.py", line 153, in
main()
File "/home/user/anaconda3/lib/python3.6/site-packages/sklearn_porter/main.py", line 105, in main
estimator = joblib.load(input_path)
File "/home/user/anaconda3/lib/python3.6/site-packages/sklearn/externals/joblib/numpy_pickle.py", line 578, in load
obj = _unpickle(fobj, filename, mmap_mode)
File "/home/user/anaconda3/lib/python3.6/site-packages/sklearn/externals/joblib/numpy_pickle.py", line 508, in _unpickle
obj = unpickler.load()
File "/home/user/anaconda3/lib/python3.6/pickle.py", line 1050, in load
dispatchkey[0]
KeyError: 239

@nok
Copy link
Owner

nok commented Feb 18, 2018

Hello @aflugge ,

can you set the compression level to 0? In Python 3.x the default value is 3 I guess.

from sklearn.externals import joblib
# ...
joblib.dump(clf, 'estimator.pkl', compress=0)

Darius

@aflugge
Copy link
Author

aflugge commented Feb 19, 2018

Thanks for the reply. Setting compress=0 does not seem to make any difference. However, with "from sklearn.externals import joblib" rather than "import joblib" as I have done before, I get the different error message as below:

Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/user/anaconda3/lib/python3.6/runpy.py", line 85, in run_code
exec(code, run_globals)
File "/home/user/anaconda3/lib/python3.6/site-packages/sklearn_porter/main.py", line 153, in
main()
File "/home/user/anaconda3/lib/python3.6/site-packages/sklearn_porter/main.py", line 148, in main
with open(dest_path, 'w') as file
:
PermissionError: [Errno 13] Permission denied: '/RandomForestClassifier.js'

I did however manage to export my RandomForestClassifier from within Python with
porter = Porter(clf, language='js')
output = porter.export(embed_data=True)
print(output)
So that way it seems to work :)

@nok
Copy link
Owner

nok commented Feb 19, 2018

Okay, I'm glad that it's working now 😄,

nevertheless, apparently the module hasn't the permission to create a file. Alternatively you can use python -m sklearn_porter -i estimator.pkl --js --pipe > estimator.js to save the output to a file dynamically.

Darius

@nok nok closed this as completed Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants