amueller / introduction_to_ml_with_python

Notebooks and code for the book "Introduction to Machine Learning with Python"
7.44k stars 4.56k forks source link

mglearn error #175

Open sebgok opened 1 year ago

sebgok commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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:

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 commented 1 year ago

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 commented 1 year ago

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