Fork me on GitHub

This documentation is for scikit-learn version 0.17Other versions

If you use the software, please consider citing scikit-learn.


sklearn.datasets.fetch_mldata(dataname, target_name='label', data_name='data', transpose_data=True, data_home=None)[source]

Fetch an data set

If the file does not exist yet, it is downloaded from . does not have an enforced convention for storing data or naming the columns in a data set. The default behavior of this function works well with the most common cases:

  1. data values are stored in the column ‘data’, and target values in the column ‘label’
  2. alternatively, the first column stores target values, and the second data values
  3. the data array is stored as n_features x n_samples , and thus needs to be transposed to match the sklearn standard

Keyword arguments allow to adapt these defaults to specific data sets (see parameters target_name, data_name, transpose_data, and the examples below). data sets may have multiple columns, which are stored in the Bunch object with their original name.


dataname: :

Name of the data set on, e.g.: “leukemia”, “Whistler Daily Snowfall”, etc. The raw name is automatically converted to a URL .

target_name: optional, default: ‘label’ :

Name or index of the column containing the target values.

data_name: optional, default: ‘data’ :

Name or index of the column containing the data.

transpose_data: optional, default: True :

If True, transpose the downloaded data array.

data_home: optional, default: None :

Specify another download and cache folder for the data sets. By default all scikit learn data is stored in ‘~/scikit_learn_data’ subfolders.


data : Bunch

Dictionary-like object, the interesting attributes are: ‘data’, the data to learn, ‘target’, the classification labels, ‘DESCR’, the full description of the dataset, and ‘COL_NAMES’, the original names of the dataset columns.


Load the ‘iris’ dataset from

>>> from sklearn.datasets.mldata import fetch_mldata
>>> import tempfile
>>> test_data_home = tempfile.mkdtemp()
>>> iris = fetch_mldata('iris', data_home=test_data_home)
(150, 4)

Load the ‘leukemia’ dataset from, which needs to be transposed to respects the sklearn axes convention:

>>> leuk = fetch_mldata('leukemia', transpose_data=True,
...                     data_home=test_data_home)
(72, 7129)

Load an alternative ‘iris’ dataset, which has different names for the columns:

>>> iris2 = fetch_mldata('datasets-UCI iris', target_name=1,
...                      data_name=0, data_home=test_data_home)
>>> iris3 = fetch_mldata('datasets-UCI iris',
...                      target_name='class', data_name='double0',
...                      data_home=test_data_home)
>>> import shutil
>>> shutil.rmtree(test_data_home)