I keep getting the error
ModuleNotFoundError: No module named 'sklearn.externals.six'
when running the code below:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import pandas as pd
import mglearn
import numpy as np
from IPython.display import display
import matplotlib as pl
import sklearn
iris_dataset = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris_dataset['data'], iris_dataset['target'], random_state=0)
iris_dataframe = pd.DataFrame(X_train, columns=iris_dataset.feature_names)
pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15), marker='o', hist_kwds={'bins':20}, s=60, alpha=.8, cmap=mglearn.cm3)
Is there a module I haven't imported or installed?
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.
I'm coming late, but this is due to the mglearn package (which internally tries to import six).
You must have an old version, because their versions posted on github don't have this issue. Perhaps from a CD coming with the book...
To fix the issue do something along the lines of:
pip install --upgrade mglearn
You can use something like below..
from six import StringIO
Downgrade your scikit-learn version:
In jupyter notebook:
!pip install --upgrade scikit-learn==0.20.3
In terminal:
pip install --upgrade scikit-learn==0.20.3
After that, the code will recognize the sklearn.external.six module.
module sklearn.externals.six was removed in version 0.23. if you want to use this module, you have to downgrade to version 0.22 or lower.
It will be in pandas 0.22 module as after upgradation of version , it was removed i.e. sklearn.external.six . you can check documentation if still confused.
ModuleNotFoundError: No module named 'sklearn.externals'; 'sklearn' is not a package
I had this error show up and tried everything here. Eventually realized that I had named a file "sklearn.py" in the directory...
You may try this:-
import six
import sys
sys.modules['sklearn.externals.six'] = six
It worked for me.
Courtesy - https://github.com/alkaline-ml/pmdarima/issues/355
Depending on which IDE you're using but if it is spyder then you have to add a spyder kernel as must to your python installation using the following code: pip install spyder-kernels
Replace the header fixed for me
import six
pip install --upgrade scikit-learn==0.20.3