handson-ml
handson-ml copied to clipboard
ImportError: cannot import name 'fetch_mldata' from 'sklearn.datasets'
I've been working my way through this book on OSX, and everything comes to a grinding halt on page 81 where it says:
The following code fetches the MNIST dataset: >>> from sklearn.datasets import fetch_mldata
What I get when I input this is:
ImportError: cannot import name 'fetch_mldata' from 'sklearn.datasets' (/usr/local/homebrew/Cellar/python/3.7.5/...
I tried with python 2 (and 3). Tried upgrading Homebrew, re-installing sklearn. I haven't seen this exact error show up anywhere else, and I'm pretty much out of ideas. It's a bit disheartening to be stopped dead having barely got started :(. Any help?
Hi Blosberg,
Thanks for your feedback. Check out issue #301, especially this comment and the one after that.
In short, fetch_mldata()
is dead because it relied on a website that died. You need to replace it with fetch_openml()
, which relies on https://openml.org, which is alive and kicking. Unfortunately, it's not just a drop-in replacement, since there are little subtleties you need to watch out for (as explained in the comments).
If you get stuck, please check out the Jupyter notebooks in this project, as I try to keep them up to date, and when things break (as they sometimes do when time passes and libraries and websites evolve), I add comments in the Jupyter notebooks to explain what changed and what to do about it.
Also try searching in this project's issues as some similar questions may already have been answered in the past.
I hope this helps! Enjoy learning ML! :)
Hi Aurelien. Thanks for the quick reply, and yes, the change from that comment seems to suffice. When I looked through the project's issues I was looking for things related to "fetch_mldata", and didn't see any matches; without knowing the cause, I only had the error message to go by. The issue title is now identical to the error message that shows up when one uses the previous command --hopefully that will help future users find their way to Issue #301 Thanks!
That's very helpful, thanks @Blosberg !
If I can make a suggestion: It might be helpful to have an issue label (like "update"/"antiquated", or "version_sensitive" or s.t. like that) to indicate dependencies from older versions of the text going out of date. As you say, as time passes libraries and websites inevitably change, so I imagine there might be more issues like this in later chapters, since I'm using a somewhat-older version of the text. If more things are breaking, then I can guess it will have been addressed somewhere, but since there are currently 380 closed issues in the repo, without a keyword match it's hard to find the right one. If I could filter for Issues with an "update" label, that would help to narrow it down.
In the latest version of scikit-learn (version 0.23.1), there is nothing named "fetch_mldata()". (That was present in the previous version of 0.19. )
In the latest version, we need to use fetch_openml().
from sklearn.datasets import fetch_openml
dataset = fetch_openml("mnist_784")
I was having difficulty opening the mnist dataset which was earlier (older version) to be imported as: from sklearn.datasets import fetch_mldata dataset = fetch_mldata("MNIST Original")
If you are still facing difficulty, try uninstalling and installing the newer version again as:
pip uninstall scikit-learn
pip install scikit-learn==0.23.1
In the latest version of scikit-learn (version 0.23.1), there is nothing named "fetch_mldata()". (That was present in the previous version of 0.19. )
In the latest version, we need to use fetch_openml().
from sklearn.datasets import fetch_openml dataset = fetch_openml("mnist_784") I was having difficulty opening the mnist dataset which was earlier (older version) to be imported as: from sklearn.datasets import fetch_mldata dataset = fetch_mldata("MNIST Original")
If you are still facing difficulty, try uninstalling and installing the newer version again as:
pip uninstall scikit-learn pip install scikit-learn==0.23.1
In the latest version of scikit-learn (version 0.23.1), there is nothing named "fetch_mldata()". (That was present in the previous version of 0.19. )
In the latest version, we need to use fetch_openml().
from sklearn.datasets import fetch_openml dataset = fetch_openml("mnist_784")
I was having difficulty opening the mnist dataset which was earlier (older version) to be imported as: from sklearn.datasets import fetch_mldata dataset = fetch_mldata("MNIST Original")
If you are still facing difficulty, try uninstalling and installing the newer version again as:
pip uninstall scikit-learn pip install scikit-learn==0.23.1
scikit-learn version: 0.24.1
I tried fetch_openml('mnist_784')
and fetch_openml('MNIST')
, got
OpenMLError: No active dataset mnist found.
If not limited to librarysklearn
, try tensorflow
import tensorflow as tf
mnist = tf.keras.datasets.mnist.load_data(path="mnist.npz")
Hi @kailichou ,
I'm just tried both fetch_openml("mnist_784")
and keras.datasets.mnist.load_data()
and they worked fine. Perhaps you ran into a temporary server-side error?
Could you please try again?
OS: Windows 10 python: 3.8.9 scikit-learn: 0.24.2 VPN: yes
Hi @ageron , I tried fetch_openml('mnist_784')
, it worked.
Thanks
Use python 3.7 And use all pip of python
On Tue, 11 May, 2021, 1:03 pm kailichou, @.***> wrote:
OS: Windows 10 python: 3.8.9 scikit-learn: 0.24.2 VPN: yes
Hi @ageron https://github.com/ageron , I tried fetch_openml('mnist_784'), it worked. Thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/529#issuecomment-837992696, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO3OVZNNSBF533QWDCKAC73TNDMWBANCNFSM4J4CBYYQ .