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

mglearn error #175

Open
sebgok opened this issue Mar 13, 2023 · 4 comments
Open

mglearn error #175

sebgok opened this issue Mar 13, 2023 · 4 comments

Comments

@sebgok
Copy link

sebgok commented Mar 13, 2023

Hi,
I am not able to practice the codes in the book because I am stuck with importing mglearn. (I am using PyCharm). Here is the error message I receive:

Traceback (most recent call last):
File "/Users/sebgok/PycharmProjects/Book/sampleDatasets.py", line 4, in
import mglearn
File "/Users/sebgok/PycharmProjects/Book/venv/lib/python3.8/site-packages/mglearn/init.py", line 1, in
from . import plots
File "/Users/sebgok/PycharmProjects/Book/venv/lib/python3.8/site-packages/mglearn/plots.py", line 2, in
from .plot_interactive_tree import plot_tree_progressive, plot_tree_partition
File "/Users/sebgok/PycharmProjects/Book/venv/lib/python3.8/site-packages/mglearn/plot_interactive_tree.py", line 6, in
from sklearn.externals.six import StringIO # doctest: +SKIP
ModuleNotFoundError: No module named 'sklearn.externals.six'

@jangboolee
Copy link

Also getting the same issue. I made sure I installed mglearn into my environment using pip, but I am unable to import mglearn:

ImportError                               Traceback (most recent call last)
Cell In[24], line 4
      2 import matplotlib.pyplot as plt
      3 import pandas as pd
----> 4 import mglearn
      5 from IPython.display import display

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\__init__.py:1](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/__init__.py:1)
----> 1 from . import plots
      2 from . import tools
      3 from .plots import cm3, cm2

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\plots.py:5](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/plots.py:5)
      3 from .plot_animal_tree import plot_animal_tree
      4 from .plot_rbf_svm_parameters import plot_svm
----> 5 from .plot_knn_regression import plot_knn_regression
      6 from .plot_knn_classification import plot_knn_classification
      7 from .plot_2d_separator import plot_2d_classification, plot_2d_separator

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\plot_knn_regression.py:7](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/plot_knn_regression.py:7)
      4 from sklearn.neighbors import KNeighborsRegressor
      5 from sklearn.metrics import euclidean_distances
----> 7 from .datasets import make_wave
      8 from .plot_helpers import cm3

@Qujixiang
Copy link

Also getting the same issue. I made sure I installed mglearn into my environment using pip, but I am unable to import mglearn:

ImportError                               Traceback (most recent call last)
Cell In[24], line 4
      2 import matplotlib.pyplot as plt
      3 import pandas as pd
----> 4 import mglearn
      5 from IPython.display import display

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\__init__.py:1](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/__init__.py:1)
----> 1 from . import plots
      2 from . import tools
      3 from .plots import cm3, cm2

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\plots.py:5](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/plots.py:5)
      3 from .plot_animal_tree import plot_animal_tree
      4 from .plot_rbf_svm_parameters import plot_svm
----> 5 from .plot_knn_regression import plot_knn_regression
      6 from .plot_knn_classification import plot_knn_classification
      7 from .plot_2d_separator import plot_2d_classification, plot_2d_separator

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\plot_knn_regression.py:7](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/plot_knn_regression.py:7)
      4 from sklearn.neighbors import KNeighborsRegressor
      5 from sklearn.metrics import euclidean_distances
----> 7 from .datasets import make_wave
      8 from .plot_helpers import cm3

Env:

  • macOS
  • python3.11

Quick fix:

  1. degrade scikit-learn version cause load_boston was deprecated since version 1.2.0: pip3 install scikit-learn==1.1.3.
  2. if you are using python3.7 below, you can degrade numpy version to a version prior to 1.20.
  3. if you are using python3.8 above, you should modify np.bool to np.bool_ in mglearn/datasets.py cause np.bool was deprecated and replaced by np.bool_ since version 1.20.
# original code
mask = np.ones(len(X), dtype=np.bool)
# modified code
mask = np.ones(len(X), dtype=np.bool_)

@jangboolee
Copy link

Also getting the same issue. I made sure I installed mglearn into my environment using pip, but I am unable to import mglearn:

ImportError                               Traceback (most recent call last)
Cell In[24], line 4
      2 import matplotlib.pyplot as plt
      3 import pandas as pd
----> 4 import mglearn
      5 from IPython.display import display

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\__init__.py:1](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/__init__.py:1)
----> 1 from . import plots
      2 from . import tools
      3 from .plots import cm3, cm2

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\plots.py:5](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/plots.py:5)
      3 from .plot_animal_tree import plot_animal_tree
      4 from .plot_rbf_svm_parameters import plot_svm
----> 5 from .plot_knn_regression import plot_knn_regression
      6 from .plot_knn_classification import plot_knn_classification
      7 from .plot_2d_separator import plot_2d_classification, plot_2d_separator

File [c:\Users\jangboo.lee\Documents\python_projects\personal\introduction_to_ml_with_python\mglearn\plot_knn_regression.py:7](file:///C:/Users/jangboo.lee/Documents/python_projects/personal/introduction_to_ml_with_python/mglearn/plot_knn_regression.py:7)
      4 from sklearn.neighbors import KNeighborsRegressor
      5 from sklearn.metrics import euclidean_distances
----> 7 from .datasets import make_wave
      8 from .plot_helpers import cm3

Env:

* `macOS`

* `python3.11`

Quick fix:

1. degrade `scikit-learn` version cause `load_boston` was deprecated since version `1.2.0`: `pip3 install scikit-learn==1.1.3`.

2. if you are using `python3.7` below, you can degrade `numpy` version to a version prior to `1.20`.

3. if you are using `python3.8` above, you should modify `np.bool` to `np.bool_` in `mglearn/datasets.py` cause `np.bool` was deprecated and replaced by `np.bool_` since version `1.20`.
# original code
mask = np.ones(len(X), dtype=np.bool)
# modified code
mask = np.ones(len(X), dtype=np.bool_)

Thank you, I confirm that the fix is working on my environment (Windows/Python 3.11/virtual environment/VS Codium)!

@mfafif0002
Copy link

Hello! How to find where is the mglearn/datasets.py located?

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

4 participants