[PYTHON] Solution for scikit-learn (sklearn) fetch_mldata error

Purpose

** Resolve errors in the fetch_mldata function (sklearn.datasets.fetch_mldata) used when downloading datasets with scikit-learn (sklearn). ** **

Error example

environment

sklearn(scikit-learn):version 0.21.2

Solution

Use fetch_openml because fetch_mldata has been deprecated and fetch_openml was created instead.

Note that fetch_mldata will be deleted in version 0.22.

sklearn.datasets.fetch_mldata to be removed in version 0.22.

Concrete example

scikit-learn can download various datasets, but here is an example of downloading the mnist dataset. Also, the language is Python.

Source code at the time of error

fetch_mldata.py


from sklearn.datasets import fetch_mldata

mnist = fetch_mldata("MNIST original", data_home=".")

x_all = mnist['data'].astype(np.float32) / 255
y_all = mnist['target'].astype(np.int32)

Modified source code

Please note that fetch_openml may be different from the dataset name used in fetch_mldata.

fetch_openml.py


from sklearn.datasets import fetch_openml

mnist_X, mnist_y = fetch_openml('mnist_784', version=1, data_home=".", return_X_y=True)

x_all = mnist_X.astype(np.float32) / 255
y_all = mnist_y.astype(np.int32)

Recommended Posts

Solution for scikit-learn (sklearn) fetch_mldata error
All-round solution for permission error (permmision error)
Solution for pip install error [Python] [Mac]
Solution for run-time error in OpenVINO IEPlugin.load ()
scikit-learn import error
[Python] for statement error