【问题标题】:Any idea how to deal with mglearn import error?知道如何处理 mglearn 导入错误吗?
【发布时间】:2023-01-24 04:39:54
【问题描述】:

我是一名新的数据科学训练营学生。最近买了一本书《Introduction to Machine Learning with Pyhton》。然而,这本书大量使用了 mglearn 库。当我想导入库时出现错误。 (您可以从下面看到。)我无法演示书中提供的示例。有什么办法可以解决这个问题吗?

提前谢谢了!。

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>

我试图从网上找到答案,但找不到任何东西。

【问题讨论】:

    标签: python machine-learning scikit-learn importerror


    【解决方案1】:

    mglearn 包似乎依赖于其依赖项中已弃用和删除的功能。希望作者会升级他们的包,或者至少更好地指定它的依赖项。您可以在 project issues webpage 上了解用户遇到的几个问题。

    为了成功导入mglearn,我是这样做的。

    在专用目录中,我创建了一个虚拟环境:

    python -m venv _venv
    

    ...然后激活它:

    . _venv/bin/activate
    

    然后我升级/安装了至少允许import mglearn 完成而不会抛出错误的包。

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

    如果您需要安装更多包,对这些包使用 --upgrade-strategy eager 可能不是最佳选择。 YMMV。

    可能有一个 conda 等同于上述过程,但我不熟悉它。

    当您使用 mglearn 功能时,可能会有更多的依赖问题需要解决。祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-30
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多