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

Scikit-Learn · Function

make_regression

Generates synthetic regression data from a random linear model. It supports configurable feature structure, informative features, target count, Gaussian noise, shuffling, and optional recovery of the true coefficients.

How it works

make_regression creates feature data and targets from a random linear model with a configurable number of nonzero regressors. It can add centered Gaussian noise, optionally produce multiple targets or the underlying coefficients, and generate either well-conditioned or low-rank feature matrices.

Syntax

make_regression(n_samples=100, n_features=100, *, n_informative=10, n_targets=1, bias=0.0, effective_rank=None, tail_strength=0.5, noise=0.0, shuffle=True, coef=False, random_state=None)

Parameters

NameTypeDescription
n_samplesintNumber of samples to generate; default 100.
n_featuresintNumber of features; default 100.
n_informativeintNumber of informative features with nonzero coefficients; default 10.
n_targetsintNumber of regression targets; default 1.
biasfloatBias term added to the output; default 0.0.
effective_rankint or NoneEffective rank of the generated feature matrix; default None.
tail_strengthfloatControls the relative importance of the fat-tail profile; default 0.5.
noisefloatStandard deviation of Gaussian noise applied to the output; default 0.0.
shuffleboolWhether to shuffle samples and features; default True.
coefboolWhether to return the underlying model coefficients; default False.
random_stateint, RandomState instance or NoneControls random generation and reproducibility; default None.

Returns

Returns X, an ndarray of shape (n_samples, n_features), and y, an ndarray of shape (n_samples,) or (n_samples, n_targets). If coef=True, also returns coef, an ndarray of shape (n_features,) or (n_features, n_targets), containing the underlying linear-model coefficients.

Key points

  • Use it to create controlled synthetic data for testing regression algorithms.
  • The default feature design is well conditioned; effective_rank and tail_strength can create a low-rank, fat-tailed structure.
  • Targets come from a random linear model, with bias allowing a nonzero intercept-like offset.
  • n_informative determines how many features receive nonzero coefficients in the generated model.
  • noise adds centered Gaussian variation to the target values, with its scale set by the noise argument.
  • shuffle independently controls whether generated samples and feature positions are randomized.

Common mistakes

  • The third return value is available only when coef=True; otherwise unpack just X and y.
  • noise controls the noise standard deviation, so nonzero noise makes generated targets differ from the noiseless linear relationship.
  • With shuffle=False, samples and features retain their generated ordering rather than being shuffled.

Example: Generate synthetic regression data

from sklearn.datasets import make_regression
from sklearn.linear_model import LinearRegression

X, y = make_regression(
    n_samples=100,
    n_features=4,
    n_informative=2,
    noise=1.0,
    random_state=42,
)
model = LinearRegression().fit(X, y)
print(model.coef_.shape)

Creates reproducible synthetic regression data and fits a linear model to it.

When to use it

Create small deterministic datasets for examples and tests.

Regression model testing

Vary sample size, feature count, informativeness, and noise to compare regressors.

Algorithm benchmarking

Generate targets with n_targets greater than one.

Multiple-output regression

Study model behavior on well-conditioned or low-rank feature matrices.

Feature-structure experiments

Interview questions

QWhat does make_regression generate?

make_regression generates synthetic regression data by applying a random linear model to generated features, using n_informative nonzero regressors. It can also add Gaussian noise to the outputs.

Follow-up: How would you inspect the true model? Set coef=True and capture the third returned value, which contains the underlying coefficients.

QWhat shapes does the function return?

X has shape (n_samples, n_features). y has shape (n_samples,) for one target or (n_samples, n_targets) for multiple targets.

Follow-up: What changes when n_targets is greater than one? The target matrix becomes two-dimensional, with one column per generated target.

QHow do reproducibility and coefficient output work?

random_state controls the random generation and makes results reproducible when given a fixed integer. The function returns X and y by default, and additionally coefficients when coef=True.

Follow-up: How can you create a noisy but reproducible problem? Pass both a nonzero noise value and a fixed random_state.

  • make_low_rank_matrix
  • make_friedman1
  • make_sparse_uncorrelated

Source: make_regression. Checked 2026-10-15.