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

Scikit-Learn · Function

make_blobs

Generates synthetic multiclass data as isotropic Gaussian clusters. It returns feature samples and integer cluster labels, with optional generated center coordinates.

How it works

make_blobs constructs a synthetic multiclass dataset by sampling points around isotropic Gaussian centers. You can choose how many samples and features to create, specify centers or let them be generated, control cluster spread, shuffle the rows, and optionally receive the generated center coordinates.

Syntax

sklearn.datasets.make_blobs(n_samples=100, n_features=2, *, centers=None, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, random_state=None, return_centers=False)

Parameters

NameTypeDescription
n_samplesint or array-like of int, default=100Total number of samples, or an array specifying the sample count for each cluster.
n_featuresint, default=2Number of features in each sample.
centersint or array-like of shape (n_centers, n_features), default=NoneNumber of generated centers or fixed center locations.
cluster_stdfloat or array-like of float, default=1.0Standard deviation of each cluster.
center_boxtuple of float (min, max), default=(-10.0, 10.0)Minimum and maximum bounds for randomly generated center coordinates.
shufflebool, default=TrueWhether to randomize the sample order.
random_stateint, RandomState instance or None, default=NoneControls reproducible random generation.
return_centersbool, default=FalseWhether to include the generated centers in the result.

Returns

Returns X, an ndarray of shape (n_samples, n_features), and y, an ndarray of shape (n_samples, containing integer cluster-membership labels. If return_centers=True, it also returns centers, an ndarray of shape (n_centers, n_features).

Key points

  • Use this generator to create synthetic, normally distributed clusters for clustering experiments.
  • centers accepts either a count of randomly generated centers or explicit center coordinates.
  • cluster_std controls how widely samples are distributed around their centers.
  • center_box limits randomly generated center coordinates to the specified interval.
  • shuffle determines whether generated rows are randomized before being returned.
  • The y output assigns an integer cluster-membership label to every sample.

Common mistakes

  • The center-coordinate array is omitted unless return_centers is enabled.

Example: Generate labeled Gaussian clusters

from sklearn.datasets import make_blobs

X, y = make_blobs(
    n_samples=120,
    centers=3,
    n_features=2,
    cluster_std=0.6,
    random_state=0,
)
print(X.shape, y.shape)

Creates 120 two-feature samples around three Gaussian cluster centers and returns their cluster labels.

When to use it

Clustering demonstrations

Create controlled labeled data for validating clustering algorithms.

Reproducible experiments

Produce repeatable datasets for examples and tests.

Synthetic benchmark generation

Compare models under different cluster spreads and locations.

Interview questions

QWhat does make_blobs return?

It returns X, the generated samples with shape (n_samples, n_features), and y, integer labels identifying each sample's cluster. If return_centers=True, it also returns the generated center coordinates.

Follow-up: How can the number of samples differ by cluster?

QHow does the centers parameter work?

Set centers to an integer to request that many generated centers, or pass an array-like value containing fixed center locations. When centers are generated, center_box bounds their coordinates.

Follow-up: How would you make cluster sizes unequal?

QHow do you control cluster dispersion?

cluster_std controls the standard deviation of the clusters and can be one float or an array-like value. A single float applies the same spread to every cluster, while per-cluster values allow different spreads.

Follow-up: What does random_state control?

  • make_classification
  • make_circles
  • make_moons

Source: make_blobs — scikit-learn 1.9.1 documentation. Checked 2026-10-15.