Supervised LearningLinear RegressionRegression

Lasso Regression (L1)

Primary task · Regression

Lasso Regression (L1) is a supervised learning method in the linear regression family. This page summarizes its mechanism, practical uses, important trade-offs, and a browser-based concept explorer.

← Directory
Visual intuition

From data to learned behaviour

Lasso Regression (L1) converts patterns in observed data into a reusable prediction or representation rule. The most useful way to understand it is to watch what internal structure changes during training and how that learned structure changes outputs.

Infographic
1Data2Initial state3Optimise4Validate5InferenceTraining transforms evidence into a reusable model state
Conceptual simulation

Watch the learning mechanism form

The structure below is synchronized with the same training state used by the prediction simulation.

Mechanism view
Training control centre

Control both simulations together

Reset regenerates the synthetic data and model state. Train animates to completion. Pause freezes the animation. Train Step advances one learning stage.

Step 0 / 20
Model simulation

Inspect the learned prediction / representation

Synthetic data are generated locally in your browser.

Model description

Understand Lasso Regression (L1) after watching it learn

This section connects the animation to the actual statistical or computational idea behind the model.

Deep description

Lasso Regression (L1) Lasso Regression (L1) is a supervised learning method in the linear regression family. This page summarizes its mechanism, practical uses, important trade-offs, and a browser-based concept explorer.

What is learned. During training, the algorithm builds or adjusts the parameters and internal representation used by Lasso Regression (L1). The core learning mechanism is: Linear regression augmented with an L1 penalty on the absolute sum of weights, driving non-informative feature coefficients to exactly zero.

How training becomes inference. Prepare data → initialise the model state → evaluate the current objective → update parameters or structure → validate progress → use the final state for inference. Once training stops, the fitted state is reused on unseen inputs rather than being reconstructed from scratch. The resulting output is: A continuous numeric prediction; some probabilistic variants can also provide uncertainty or intervals.

Why practitioners use it. Performs automatic feature selection; yields highly sparse and interpretable models. Typical fits include High-dimensional genomic regression, biomarker selection, sparse econometrics.

What to verify before trusting it. Arbitrarily selects one feature among highly correlated groups and discards the rest. The visual simulation is intentionally simplified, so real use should still validate preprocessing, data independence, hyperparameters, uncertainty and task-appropriate metrics.

Internal statethe parameters and internal representation used by Lasso Regression (L1)
Typical outputA continuous numeric prediction; some probabilistic variants can also provide uncertainty or intervals.
Good fitHigh-dimensional genomic regression, biomarker selection, sparse econometrics.
Main cautionArbitrarily selects one feature among highly correlated groups and discards the rest.
1Training data→
2Learning objective→
3Internal model state→
4Prediction / representation→
5Evaluation
Intuition

What the model is trying to learn

Lasso Regression (L1) converts patterns in observed data into a reusable prediction or representation rule. The most useful way to understand it is to watch what internal structure changes during training and how that learned structure changes outputs.

Mathematical lens

Core logic

Linear regression augmented with an L1 penalty on the absolute sum of weights, driving non-informative feature coefficients to exactly zero. The mathematical objective determines which model states are considered better, while regularisation and validation constrain how much complexity should be trusted.

Training sequence

How learning progresses

Prepare data → initialise the model state → evaluate the current objective → update parameters or structure → validate progress → use the final state for inference.

Original mechanism

Taxonomy description

Linear regression augmented with an L1 penalty on the absolute sum of weights, driving non-informative feature coefficients to exactly zero.

Evaluation guide

How to evaluate this model responsibly

ValidationK-Fold; Group K-Fold for repeated entities; time-aware splits for temporal targets.
MetricsMAE and RMSE together, plus R²; inspect residuals rather than trusting one aggregate score.
HPORandom/Bayesian optimisation for continuous hyperparameters; use nested CV when model selection is intensive.
Post-processingInverse target transforms, clipping only with domain justification, and prediction intervals where uncertainty matters.
Hyperparameters

Key parameters

alphaTypical: 1.0

L1 regularization strength.

max_iterTypical: 1000+

Coordinate-descent iteration cap.

selectionTypical: cyclic

Coefficient update order.

Use & trade-offs

Where it fits

Typical applications

High-dimensional genomic regression, biomarker selection, sparse econometrics.

Strengths

Performs automatic feature selection; yields highly sparse and interpretable models.

Limitations

Arbitrarily selects one feature among highly correlated groups and discards the rest.

Code example

Minimal Python implementation

# Purpose: demonstrate Lasso Regression (L1) with a small, inspectable example.
# Follow the comments and printed stages to connect each operation with its result.
# Import the library or helper used in this example.
from sklearn.datasets import make_regression
# Import the library or helper used in this example.
from sklearn.linear_model import Lasso
# Import the library or helper used in this example.
from sklearn.model_selection import train_test_split
# Import the library or helper used in this example.
from sklearn.metrics import r2_score

# Print this intermediate result so you can verify the workflow step by step.
print("STEP 1 · Create a sparse-signal regression dataset")
# Store this intermediate value with a descriptive name for the next step.
X, y = make_regression(n_samples=100, n_features=8, n_informative=4, noise=10, random_state=42)
# Separate training and evaluation data before fitting the model.
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=.25, random_state=42)
# Print this intermediate result so you can verify the workflow step by step.
print("Train/test shapes:", Xtr.shape, Xte.shape)
# Print this intermediate result so you can verify the workflow step by step.
print("STEP 2 · Fit Lasso with L1 penalty")
# Configure the estimator or pipeline with the chosen settings.
model = Lasso(alpha=1.0, max_iter=5000).fit(Xtr, ytr)
# Print this intermediate result so you can verify the workflow step by step.
print("Non-zero coefficients:", int((model.coef_ != 0).sum()))
# Print this intermediate result so you can verify the workflow step by step.
print("STEP 3 · Evaluate unseen rows")
# Generate predictions from the fitted model.
pred = model.predict(Xte)
# Print this intermediate result so you can verify the workflow step by step.
print("Test R2:", round(r2_score(yte, pred), 3))
Expected / representative output
STEP 1 · Create a sparse-signal regression dataset
Train/test shapes: (75, 8) (25, 8)
STEP 2 · Fit Lasso with L1 penalty
Non-zero coefficients: 5
STEP 3 · Evaluate unseen rows
Test R2: 0.993