Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'joblib' from 'sklearn.externals'

I am trying to load my saved model from s3 using joblib

import pandas as pd  import numpy as np import json import subprocess import sqlalchemy from sklearn.externals import joblib  ENV = 'dev' model_d2v = load_d2v('model_d2v_version_002', ENV)  def load_d2v(fname, env):     model_name = fname     if env == 'dev':         try:              model=joblib.load(model_name)         except:             s3_base_path='s3://sd-flikku/datalake/doc2vec_model'             path = s3_base_path+'/'+model_name             command = "aws s3 cp {} {}".format(path,model_name).split()             print('loading...'+model_name)             subprocess.call(command)             model=joblib.load(model_name)     else:         s3_base_path='s3://sd-flikku/datalake/doc2vec_model'         path = s3_base_path+'/'+model_name         command = "aws s3 cp {} {}".format(path,model_name).split()         print('loading...'+model_name)         subprocess.call(command)         model=joblib.load(model_name)     return model 

But i was facing this error:

    from sklearn.externals import joblib ImportError: cannot import name 'joblib' from 'sklearn.externals' (C:\Users\prane\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\externals\__init__.py) 

Then i tried installing joblib directly by doing

import joblib 

but it gave me this error

Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "<stdin>", line 8, in load_d2v_from_s3   File "/home/ec2-user/.local/lib/python3.7/site-packages/joblib/numpy_pickle.py", line 585, in load     obj = _unpickle(fobj, filename, mmap_mode)   File "/home/ec2-user/.local/lib/python3.7/site-packages/joblib/numpy_pickle.py", line 504, in _unpickle     obj = unpickler.load()   File "/usr/lib64/python3.7/pickle.py", line 1088, in load     dispatch[key[0]](self)   File "/usr/lib64/python3.7/pickle.py", line 1376, in load_global     klass = self.find_class(module, name)   File "/usr/lib64/python3.7/pickle.py", line 1426, in find_class     __import__(module, level=0) ModuleNotFoundError: No module named 'sklearn.externals.joblib' 

Can you tell me how to solve this? Thanks in advance

like image 613
Praneeth Sai Avatar asked May 19 '20 14:05

Praneeth Sai


People also ask

What is Joblib Sklearn?

Sklearn Joblib SummaryYou can connect joblib to the Dask backend to scale out to a remote cluster for even faster processing times. You can use XGBoost-on-Dask and/or dask-ml for distributed machine learning training on datasets that don't fit into local memory.

How do you solve no modules named Sklearn externals 6?

You can use the official six package. First Install six using: pip install six and then you import the module. No need to downgrade scikit-learn.

What is Joblib in Python?

Joblib is a set of tools to provide lightweight pipelining in Python. In particular: transparent disk-caching of functions and lazy re-evaluation (memoize pattern) easy simple parallel computing.


1 Answers

You should directly use

import joblib 

instead of

from sklearn.externals import joblib 
like image 189
Smruthi Vuppuluri Avatar answered Sep 19 '22 16:09

Smruthi Vuppuluri