Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Function

make_classification

Generates a synthetic n-class classification problem with controllable class structure, feature categories, and noise. It returns feature data and integer labels by default.

How it works

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.

Syntax

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)

Parameters

NameTypeDescription
n_samplesintNumber of samples to generate; default 100.
n_featuresintTotal number of features; default 20.
n_informativeintNumber of informative features; default 2.
n_redundantintNumber of redundant features; default 2.
n_repeatedintNumber of repeated features; default 0.
n_classesintNumber of classes or labels; default 2.
n_clusters_per_classintNumber of clusters per class; default 2.
weightsarray-like or NoneClass proportions, with shape (n_classes,) or (n_classes - 1,); default None.
flip_yfloatFraction of samples whose labels are assigned randomly; default 0.01.
class_sepfloatFactor multiplying the hypercube size; default 1.0.
hypercubeboolWhether to place cluster vertices on a hypercube; default True.
shiftfloat or array-likeFeature shift; default 0.0.

Returns

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.

Key points

  • Use it to synthesize labeled classification data for experiments, demonstrations, and estimator tests.
  • Class structure starts as normally distributed clusters positioned around hypercube vertices.
  • The generator can make the problem harder through dependent features and several noise mechanisms.
  • Features not designated informative, redundant, or repeated carry random noise.
  • n_samples controls how many rows are generated.
  • n_features determines the width of the generated feature matrix.
  • weights controls the class proportions when constructing the target labels.

Example: Generate a multiclass dataset

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.

When to use it

Estimator experiments

Create controlled benchmark data for comparing classifiers under known class structure.

Feature-selection demonstrations

Generate examples with redundant, repeated, or uninformative features to demonstrate feature selection.

Teaching and testing

Produce reproducible labeled inputs for tutorials and tests.

Interview questions

QWhat kind of data does make_classification generate?

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.

QWhat does the function return?

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.

QHow do the feature categories differ?

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_blobs
  • sklearn.datasets.make_multilabel_classification
  • sklearn.model_selection.train_test_split

Source: make_classification. Checked 2026-10-15.