Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'fetch_mldata' from 'sklearn.datasets' #529

Open
Blosberg opened this issue Dec 17, 2019 · 10 comments
Open

Comments

@Blosberg
Copy link

Blosberg commented Dec 17, 2019

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?

@ageron
Copy link
Owner

ageron commented Dec 18, 2019

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! :)

@Blosberg Blosberg changed the title cannot import name 'fetch_mldata' from 'sklearn.datasets' ImportError: cannot import name 'fetch_mldata' from 'sklearn.datasets' Dec 18, 2019
@Blosberg
Copy link
Author

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!

@ageron
Copy link
Owner

ageron commented Dec 20, 2019

That's very helpful, thanks @Blosberg !

@Blosberg
Copy link
Author

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.

@Blosberg Blosberg reopened this Dec 20, 2019
@geegatomar
Copy link

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

@abhay382
Copy link

abhay382 commented Aug 1, 2020

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

@kailichou
Copy link

kailichou commented Apr 28, 2021

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")

@ageron
Copy link
Owner

ageron commented May 4, 2021

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?

@kailichou
Copy link

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

@abhay382
Copy link

abhay382 commented May 11, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants