Created
April 11, 2017 02:26
-
-
Save youngsoul/fc69665c5d08e189c57c0db0e93017a6 to your computer and use it in GitHub Desktop.
Download the MNIST data as needed for the 'Hands-On Machine Learning with Scikit-Learn and TensorFlow' book
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from six.moves import urllib | |
from sklearn.datasets import fetch_mldata | |
import requests | |
requests.packages.urllib3.disable_warnings() | |
""" | |
Adapted from the Github repo: | |
https://github.com/ageron/handson-ml | |
for the 03_classification notebook. | |
This implementation uses the 'requests' package instead of URLLIB | |
""" | |
try: | |
mnist = fetch_mldata('MNIST original') | |
except urllib.error.HTTPError as ex: | |
print("Could not download MNIST data from mldata.org, trying alternative...") | |
# Alternative method to load MNIST, if mldata.org is down | |
from scipy.io import loadmat | |
mnist_alternative_url = "https://github.com/amplab/datascience-sp14/raw/master/lab7/mldata/mnist-original.mat" | |
mnist_path = "./mnist-original.mat" | |
response = requests.get(mnist_alternative_url) | |
with open(mnist_path, "wb") as f: | |
content = response.content | |
f.write(content) | |
mnist_raw = loadmat(mnist_path) | |
mnist = { | |
"data": mnist_raw["data"].T, | |
"target": mnist_raw["label"][0], | |
"COL_NAMES": ["label", "data"], | |
"DESCR": "mldata.org dataset: mnist-original", | |
} | |
print("Success!") |
where is the data saved
Is it saved as .mat file?
did not work for me
Instead Of Using this whole program use this, It works for me. Try it
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
@ [C-H-I-R-A-G] : Thanks Your Code Worked
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
did not work