Estimator experiments
Create controlled benchmark data for comparing classifiers under known class structure.
Scikit-Learn · Function
Generates a synthetic n-class classification problem with controllable class structure, feature categories, and noise. It returns feature data and integer labels by default.
The function constructs normally distributed clusters around vertices of an informative-feature hypercube, assigns clusters to classes, and can add redundant, repeated, noisy, or transformed features. It returns either the generated feature matrix and labels or, when configured otherwise, a combined dataset.
sklearn.datasets.make_classification(n_samples=100, n_features=20, *, n_informative=2, n_redundant=2, n_repeated=0, n_classes=2, n_clusters_per_class=2, weights=None, flip_y=0.01, class_sep=1.0, hypercube=True, shift=0.0, scale=1.0, shuffle=True, random_state=None, return_X_y=True)| Name | Type | Description |
|---|---|---|
n_samples | int | Number of samples to generate; default 100. |
n_features | int | Total number of features; default 20. |
n_informative | int | Number of informative features; default 2. |
n_redundant | int | Number of redundant features; default 2. |
n_repeated | int | Number of repeated features; default 0. |
n_classes | int | Number of classes or labels; default 2. |
n_clusters_per_class | int | Number of clusters per class; default 2. |
weights | array-like or None | Class proportions, with shape (n_classes,) or (n_classes - 1,); default None. |
flip_y | float | Fraction of samples whose labels are assigned randomly; default 0.01. |
class_sep | float | Factor multiplying the hypercube size; default 1.0. |
hypercube | bool | Whether to place cluster vertices on a hypercube; default True. |
shift | float or array-like | Feature shift; default 0.0. |
When return_X_y=True, returns X with shape (n_samples, n_features) and y with shape (n_samples,), containing integer class labels. When return_X_y=False, returns a Bunch.
from sklearn.datasets import make_classification
X, y = make_classification(
n_samples=200,
n_features=6,
n_informative=3,
n_redundant=1,
n_classes=3,
n_clusters_per_class=1,
random_state=42,
)
print(X.shape, y.shape)Creates a reproducible three-class dataset with six features and returns its feature matrix and integer labels.
Create controlled benchmark data for comparing classifiers under known class structure.
Generate examples with redundant, repeated, or uninformative features to demonstrate feature selection.
Produce reproducible labeled inputs for tutorials and tests.
make_classification generates a random n-class classification problem. It builds Gaussian clusters around vertices of an informative-dimensional hypercube, assigns clusters to classes, and can add feature dependence and noise.
Follow-up: How can you create multiple clusters per class? Set n_clusters_per_class to the desired number, subject to the documented relationship between clusters, classes, and informative dimensions.
With return_X_y=True, the function returns X and y: X has shape (n_samples, n_features), and y contains integer class-membership labels. Setting return_X_y=False returns a Bunch containing the generated data and target.
Follow-up: What should code do if it needs named fields rather than tuple unpacking? Set return_X_y=False and access the returned Bunch fields.
n_informative controls the features used to construct the class structure, while n_redundant contains linear combinations of informative features and n_repeated contains duplicates. Remaining features are random noise.
Follow-up: How can the feature ordering be inspected? Disable shuffling; the documentation specifies the order of informative, redundant, repeated, then noise features.
sklearn.datasets.make_blobssklearn.datasets.make_multilabel_classificationsklearn.model_selection.train_test_split