cannot import name 'fetch_mldata' from 'sklearn.datasets' (C:\Users\ASUS\anaconda3\Lib\site-packages\sklearn\datasets\__init__.py) 怎么解决
时间: 2023-11-17 07:01:14 浏览: 61
这个错误通常是因为sklearn版本更新导致fetch_mldata函数被删除了。解决方法是使用fetch_openml函数代替fetch_mldata函数。以下是修改后的代码:
```
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
```
相关问题
ImportError: cannot import name 'Axes' from 'matplotlib.axes' (F:\Users\Tianxiaofan\Anaconda3\lib\site-packages\matplotlib\axes\__init__.py)
根据引用\[1\]和引用\[2\]的信息,你遇到的问题是在导入matplotlib.pyplot时出现了ImportError: cannot import name 'fetch_mldata' from 'sklearn.datasets'的错误。这个错误的原因可能是因为fetch_mldata函数在最新版本的scikit-learn中已经被弃用了。所以你需要更新你的代码以适应最新的scikit-learn版本。
根据引用\[3\]的信息,你可以尝试以下步骤来解决这个问题:
1. 打开Anaconda Prompt,并进入你的环境。
2. 使用命令`pip uninstall matplotlib`来卸载当前安装的matplotlib。
3. 确认是否成功删除了matplotlib的文件,如果没有删除,你可以手动删除。
4. 使用命令`pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib`来重新安装matplotlib。
5. 重新打开Spyder,并尝试导入`import matplotlib.pyplot as plt`。
这样应该可以解决你遇到的问题。如果还有其他问题,请随时提问。
#### 引用[.reference_title]
- *1* *3* [ImportError: cannot import name ‘_api‘ from ‘matplotlib](https://blog.csdn.net/wmm_hhh/article/details/128050373)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [【Bug记录】ImportError: cannot import name ‘fetch_mldata‘ from ‘sklearn.datasets](https://blog.csdn.net/weixin_51545953/article/details/127382891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
D:\ANACONDA\lib\site-packages\sklearn\datasets\_openml.py:932: FutureWarning: The default value of `parser` will change from `'liac-arff'` to `'auto'` in 1.4. You can set `parser='auto'` to silence this warning. Therefore, an `ImportError` will be raised from 1.4 if the dataset is dense and pandas is not installed. Note that the pandas parser may return different data types. See the Notes Section in fetch_openml's API doc for details.
I apologize for any confusion caused. The warning you mentioned is related to the `fetch_openml` function in scikit-learn and the default value of the `parser` parameter. The warning message indicates that starting from scikit-learn version 1.4, the default value of `parser` will change from `'liac-arff'` to `'auto'`.
To silence this warning, you can explicitly set the `parser` parameter to `'auto'` when calling the `fetch_openml` function. Here's an example:
```python
from sklearn.datasets import fetch_openml
boston = fetch_openml(data_id=531, parser='auto')
```
By setting `parser='auto'`, you will avoid the warning message.
Please note that the warning message is not related to the error you encountered previously. If you are still having trouble loading the Boston dataset, please provide the specific error message so that I can help you further.
I apologize for any inconvenience caused, and I'm here to assist you with any additional questions or concerns you may have.