python 知道如何处理mglearn导入错误吗?

e0bqpujr  于 2023-01-24  发布在  Python
关注(0)|答案(1)|浏览(271)

我是一个新的数据科学训练营的学生。最近我买了一本书“介绍机器学习与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>

我试着从网上找到答案,但我什么也找不到。

kxeu7u2r

kxeu7u2r1#

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特性时,可能会有更多的依赖性问题需要解决。

相关问题