简体   繁体   中英

Any idea how to deal with mglearn import error?

I am a new data science bootcamp student. Recently I bought a book "Introduction to Machine Learning with Pyhton". However the book heavily uses mglearn library. When I want to import the library I am having an error. (You can see from below.) I can not demonstrate the examples provided from the book. Is there any way to tackle this issue?

Many thanks in advance..

ImportError                               Traceback (most recent call last)
Cell In [3], line 1
----> 1 import mglearn

File c:\Users\murad\AppData\Local\Programs\Python\Python310\lib\site-packages\mglearn\__init__.py:1
----> 1 from . import plots
      2 from . import tools
      3 from .plots import cm3, cm2

File c:\Users\murad\AppData\Local\Programs\Python\Python310\lib\site-packages\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\murad\AppData\Local\Programs\Python\Python310\lib\site-packages\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
     11 def plot_knn_regression(n_neighbors=1):

File c:\Users\murad\AppData\Local\Programs\Python\Python310\lib\site-packages\mglearn\datasets.py:5
      3 import os
      4 from scipy import signal
----> 5 from sklearn.datasets import load_boston
      6 from sklearn.preprocessing import MinMaxScaler, PolynomialFeatures
      7 from .make_blobs import make_blobs

File c:\Users\murad\AppData\Local\Programs\Python\Python310\lib\site-packages\sklearn\datasets\__init__.py:156, in __getattr__(name)
    105 if name == "load_boston":
    106     msg = textwrap.dedent(
    107         """
    108         `load_boston` has been removed from scikit-learn since version 1.2.
   (...)
    154         """
    155     )
--> 156     raise ImportError(msg)
    157 try:
    158     return globals()[name]

ImportError: 
`load_boston` has been removed from scikit-learn since version 1.2.

The Boston housing prices dataset has an ethical problem: as
investigated in [1], the authors of this dataset engineered a
non-invertible variable "B" assuming that racial self-segregation had a
positive impact on house prices [2]. Furthermore the goal of the
research that led to the creation of this dataset was to study the
impact of air quality but it did not give adequate demonstration of the
validity of this assumption.

The scikit-learn maintainers therefore strongly discourage the use of
...
[2] Harrison Jr, David, and Daniel L. Rubinfeld.
"Hedonic housing prices and the demand for clean air."
Journal of environmental economics and management 5.1 (1978): 81-102.
<https://www.researchgate.net/publication/4974606_Hedonic_housing_prices_and_the_demand_for_clean_air>

I tried to find an answer from online but I could not find anything.

The mglearn package seems to rely on deprecated and removed features of its dependencies. Hopefully the authors will upgrade their package, or at least better specify its dependencies. You can read about the several problems users are having on the project issues webpage .

To successfully import mglearn , here's what I did.

In a dedicated directory I created a virtual environment with:

python -m venv _venv

... and then activated it:

. _venv/bin/activate

I then upgraded/installed the packages that at least allow import mglearn to complete without throwing an error.

python -m pip install --upgrade --upgrade-strategy eager pip setuptools ipython mglearn "scikit-learn==1.0.2" "joblib<0.12"

If you need to install more packages, using --upgrade-strategy eager for those packages may not be the best choice. YMMV.

There is probably a conda equivalent of the above procedure, but I'm not familiar with it.

As you use the mglearn features, it's possible there may be further dependency problems that need to be resolved. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM