Download benchmark data
A notebook or script needs a public benchmark dataset by its OpenML name.
Scikit-Learn · Function
Downloads a dataset from OpenML by name or numeric ID. It can cache the download and return either a dataset container or separate features and target.
fetch_openml identifies an OpenML dataset either by its numeric ID or by name, optionally constrained to a version. It downloads and caches the data, then returns either a Bunch containing dataset metadata and arrays or, when return_X_y is enabled, a two-item feature/target result; frame and parser options control representation and CSV parsing.
sklearn.datasets.fetch_openml(name: str | None = None, *, version: str | int = 'active', data_id: int | None = None, data_home: str | PathLike | None = None, target_column: str | List | None = 'default-target', cache: bool = True, return_X_y: bool = False, as_frame: str | bool = 'auto', n_retries: int = 3, delay: float = 1.0, parser: str = 'auto', read_csv_kwargs: Dict | None = None)| Name | Type | Description |
|---|---|---|
name | str or None, default=None | String identifier of the dataset. |
version | str or int, default='active' | Dataset version; may be 'active' or an integer and requires name. |
data_id | int or None, default=None | OpenML ID of the dataset. |
data_home | str, path-like, or None, default=None | Alternative download and cache directory. |
target_column | str, list, or None, default='default-target' | Column name or column names to use as the target. |
cache | bool, default=True | Whether to use the local cache. |
return_X_y | bool, default=False | Whether to return features and target separately. |
as_frame | str or bool, default='auto' | Whether to represent data as pandas objects; 'auto' selects automatically. |
n_retries | int, default=3 | Number of download retries. |
delay | float, default=1.0 | Delay between retries. |
parser | str, default='auto' | CSV parsing mode. |
read_csv_kwargs | dict or None, default=None | Additional keyword arguments for CSV reading. |
By default, a Bunch containing the loaded dataset and metadata; with return_X_y=True, returns the data and target separately.
from sklearn.datasets import fetch_openml
X, y = fetch_openml(
name="mnist_784",
version=1,
return_X_y=True,
as_frame=False,
)
print(X.shape, y.shape)Downloads a specific OpenML dataset version and returns its features and target as separate objects.
A notebook or script needs a public benchmark dataset by its OpenML name.
A pipeline must use exactly the dataset revision used during development.
Repeated local experiments should avoid downloading the same files again.
A model workflow needs tabular pandas-compatible inputs and outputs.
It accepts either a dataset name or an OpenML data_id, but not both. A name may also be paired with a version; data_id is the most specific retrieval method.
Follow-up: How would you make a training job reproducible? Pin the dataset’s numeric version, and use a stable cache location if appropriate.
By default, the function returns a Bunch-like container with the downloaded dataset and related information. Setting return_X_y=True instead returns the feature data and target separately.
Follow-up: When would as_frame=True be useful? Use it when pandas-compatible DataFrame and Series representations are preferable, especially for heterogeneous columns.
data_home selects the download and cache directory. If it is omitted, scikit-learn stores downloaded data under subdirectories of ~/scikit_learn_data.
Follow-up: What operational concern follows from caching? A shared or persistent cache can avoid repeated downloads, while an explicit data_home makes the location predictable.
sklearn.datasets.load_irissklearn.datasets.get_data_homesklearn.datasets.clear_data_home