cannot import name 'joblib' from 'sklearn.externals' (C:\Users\32184\miniconda3\Lib\site-packages\sklearn\externals\__init__.py)
时间: 2023-11-30 08:01:59 浏览: 30
这个错误通常是由于scikit-learn版本不兼容导致的。在较新的版本中,joblib已经被移动到了sklearn.utils中,因此在导入时会出现错误。解决这个问题的方法是安装一个旧版本的scikit-learn,或者更新你的代码以使用新版本的scikit-learn。以下是两种解决方法:
1.安装旧版本的scikit-learn
```shell
pip install scikit-learn==0.20.3
```
2.更新代码以使用新版本的scikit-learn
```python
from sklearn.utils import joblib
```
相关问题
ImportError Traceback (most recent call last) Cell In[1], line 3 1 import xgboost as xgb 2 from sklearn.model_selection import train_test_split ----> 3 from sklearn.externals import joblib 4 from sklearn.model_selection import ParameterGrid 5 from ultis import * ImportError: cannot import name 'joblib' from 'sklearn.externals' (e:\python\Lib\site-packages\sklearn\externals\__init__.py)
这个错误是因为你使用的Sklearn版本不同于你的代码中使用的版本。在Sklearn 0.23版本中,joblib已经从sklearn.externals中移动到了sklearn.utils中。所以你需要更新sklearn版本或者改变你的代码中的导入语句。
你可以通过以下方式导入joblib:
```python
from sklearn.utils import joblib
```
或者升级sklearn版本:
```python
!pip install --upgrade scikit-learn
```
ImportError: cannot import name 'joblib' from 'sklearn.externals' (e:\mlp\anaconda3\lib\site-packages\sklearn\externals\__init__.py)
The error message suggests that you are trying to import the `joblib` module from the `sklearn.externals` package, but it is not found in that package.
In newer versions of scikit-learn (v0.21 and above), `joblib` has been moved to a standalone package and is no longer included in `sklearn.externals`. To fix this error, you should import `joblib` from its new location:
```python
from joblib import dump, load
```
You can then use the `dump` and `load` functions to save and load your machine learning models.
If you are using an older version of scikit-learn and cannot upgrade, you can try importing `joblib` from its old location:
```python
from sklearn.externals import joblib
```
However, this is not recommended as the `sklearn.externals` module has been removed in scikit-learn v0.23 and above, and `joblib` should always be imported from its standalone package.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)