-1
import pandas as pd 
from sklearn.tree import DecisionTreeClassifier
from sklearn.externals import joblib
    
music_data = pd.read_csv('music.csv')
X = music_data.drop(columns=['genre'])
y = music_data['genre']
    
                     
model = DecisionTreeClassifier()
model.fit(X, y)
    
joblib.dump(model, 'music-recommender.joblib' )

This is the output:

Traceback (most recent call last)
    <ipython-input-28-802088a85507> in <module>
          1 import pandas as pd
          2 from sklearn.tree import DecisionTreeClassifier
    ----> 3 from sklearn.externals import joblib
          4 
          5 music_data = pd.read_csv('music.csv')

ImportError: cannot import name 'joblib' from 'sklearn.externals' (C:\Users\christian\anaconda3\lib\site-packages\sklearn\externals\__init__.py)*****

I would appreciate if someone could help out, is there another syntax that I should use to import joblib from sklearn?

Jason Rebelo Neves
  • 1,131
  • 10
  • 20
  • Does this answer your question? [ImportError: cannot import name 'joblib' from 'sklearn.externals'](https://stackoverflow.com/questions/61893719/importerror-cannot-import-name-joblib-from-sklearn-externals) – Jason Rebelo Neves Mar 06 '21 at 20:57

2 Answers2

1

I had the same problem, I never knew that joblib was already install on my machine. just replace this line of code
from sklearn.externals import joblib
with import joblib

0

The issue is here that you are trying to import joblib from scikit learn not reading csv file if you're wondering. Install joblib using pip install joblib and import it like this

import joblib
joblib.dump(model, 'music-recommender.joblib')

Remember to remove the import line from sklearn.externals. You can find more details here from the official documentation of scikit-learn.

Manash Mandal
  • 421
  • 2
  • 5