Classifier prototyping
Quickly obtain a small, well-known labeled dataset for testing a classifier.
Scikit-Learn · Function
Loads scikit-learn’s built-in Iris dataset for multi-class classification. It returns a metadata-rich Bunch by default, or data and targets directly with configurable pandas output.
load_iris provides the built-in Iris classification dataset. By default it returns a dictionary-like Bunch containing feature data, labels, names, and a description; optional flags can instead return feature and target objects directly and use pandas containers.
sklearn.datasets.load_iris(*, return_X_y=False, as_frame=False)| Name | Type | Description |
|---|---|---|
return_X_y | bool, default=False | Whether to return a tuple of data and target instead of a Bunch object. |
as_frame | bool, default=False | Whether to return pandas DataFrame or Series objects with appropriate dtypes. |
By default, a Bunch dictionary-like object containing the dataset and metadata. With return_X_y=True, returns (data, target); with as_frame=True, the data and target use pandas DataFrame or Series representations as documented.
from sklearn.datasets import load_iris
iris = load_iris(as_frame=True)
print(iris.data.shape)
print(iris.target_names.tolist())Loads the Iris dataset with feature data in a pandas DataFrame and prints its dimensions and class names.
Quickly obtain a small, well-known labeled dataset for testing a classifier.
Use named numeric columns and pandas operations during exploratory analysis.
Demonstrate dimensionality reduction or visualization on a standard dataset.
The function loads the Iris dataset for classification and, by default, returns a Bunch. The Bunch exposes feature data, classification targets, names, and dataset documentation.
Follow-up: How would you obtain pandas objects? Call load_iris(as_frame=True); the feature data becomes a pandas DataFrame and the target is a pandas DataFrame or Series as documented.
return_X_y=False is the default and returns the complete Bunch. Setting it to True returns a tuple containing data followed by target, which is convenient when metadata is unnecessary.
Follow-up: What happens if both return_X_y=True and as_frame=True are used? The tuple elements are pandas DataFrames or Series as described by the documentation.
as_frame=True requests pandas representations with appropriate numeric column dtypes. This is useful when downstream code expects DataFrame-style labels and tabular operations.
Follow-up: Does as_frame=True alone remove the Bunch? No; return_X_y controls whether the result is a tuple, while as_frame controls the representations of its data and target components.
sklearn.datasets.load_winesklearn.datasets.load_digitsThe Iris DatasetPrincipal Component Analysis (PCA) on Iris Dataset