RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • bayesopt
    • classify
    • confusionmat
    • crossvalind
    • cvpartition
    • fitclinear
    • fitctree
    • fitlm
    • kmeans
    • knnsearch
    • lasso
    • lassoglm
    • linkage
    • lscov
    • mnrfit
    • optimizableVariable
    • pdist
    • pdist2
    • perfcurve
    • predict
    • regress
    • ridge
    • squareform
    • test
    • training
    • tsne

lasso — Fit lasso or elastic-net regularized linear regression models.

lasso(X,y) fits regularized linear regression coefficients for predictor matrix X and response vector y. Columns of B correspond to ascending Lambda values, and [B,FitInfo] = lasso(...) returns MATLAB-compatible fit metadata.

Syntax

B = lasso(X, y)
B = lasso(X, y, Name, Value)
[B, FitInfo] = lasso(X, y)
[B, FitInfo] = lasso(X, y, Name, Value)

Inputs

NameTypeRequiredDefaultDescription
XNumericArrayYes—Predictor matrix with observations in rows and predictors in columns.
yNumericArrayYes—Response vector with one value per row of X.
optionsAnyVariadic—Name-value options such as Lambda, Alpha, Standardize, Intercept, Weights, CV, NumLambda, LambdaRatio, MaxIter, and RelTol.

Returns

NameTypeDescription
BNumericArrayCoefficient matrix with one column per Lambda value.
FitInfoAnyFit information structure containing Lambda, Alpha, Intercept, DF, MSE, and related fields.

Returned values from lasso depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:lasso:InvalidArgumentInputs, option names, option values, dimensions, or tolerances are malformed.lasso: invalid argument
RunMat:lasso:ConvergenceCoordinate descent cannot make numerical progress for the supplied data.lasso: convergence failure
RunMat:lasso:InternalRunMat cannot construct lasso outputs.lasso: internal error

How lasso works

  • X must be a finite real numeric matrix with observations in rows and predictors in columns. y must be a finite real vector whose length matches size(X,1).
  • Lambda accepts a nonnegative scalar or vector. RunMat sorts Lambda values in ascending order for output, matching MATLAB's FitInfo.Lambda convention.
  • When Lambda is omitted, RunMat computes a geometric regularization path using NumLambda and LambdaRatio from the largest lambda that gives an all-zero model.
  • Alpha supports lasso and elastic-net fits for values in (0,1]. Alpha=1 is lasso; smaller positive values mix in the ridge penalty.
  • Standardize and Intercept follow MATLAB's model form. If Intercept is false, RunMat disables standardization and returns zero intercepts.
  • Weights accepts a nonnegative observation-weight vector with positive total weight. Weights are normalized internally.
  • RelTol and MaxIter control coordinate-descent convergence. The Iterations FitInfo field records iterations per Lambda value.
  • CV supports "resubstitution" and positive integer K-fold cross-validation. K-fold fits add SE, LambdaMinMSE, Lambda1SE, IndexMinMSE, and Index1SE fields to FitInfo.
  • PredictorNames, DFmax, UseCovariance, and MCReps=1 are accepted for script compatibility. Tall-array ADMM behavior, covariance-matrix acceleration, and the currently unimplemented CacheSize, AbsTol, B0, U0, Rho, and Options forms reject explicitly; FitInfo.UseCovariance is false because RunMat uses direct coordinate descent.
  • Typed-integer X, y, floating parameters, and structural or logical controls are independently classified RunMat-only extensions. Integer data remains exact until a checked double solver boundary; values not exactly representable as double reject rather than round.

Examples

Fit a sparse linear model for an explicit Lambda

X = [0 1; 1 1; 2 1; 3 1; 4 1];
y = [1; 3; 5; 7; 9];
B = lasso(X, y, "Lambda", 0, "Standardize", false)

Expected output:

B is approximately [2; 0]. Use FitInfo.Intercept for the constant term.

Return FitInfo for an elastic-net path

[B,FitInfo] = lasso(X, y, "Alpha", 0.5, "Lambda", [0 0.01 0.1]);
coef0 = FitInfo.Intercept(1)

Expected output:

B has one column per Lambda value; FitInfo contains Lambda, Alpha, Intercept, DF, and MSE.

Use K-fold cross-validation

[B,FitInfo] = lasso(X, y, "CV", 5);
idx = FitInfo.IndexMinMSE;
coef = B(:,idx)

Expected output:

FitInfo includes cross-validation MSE, SE, and Lambda selection fields.

Weight observations

w = ones(size(y));
w(1:5) = 2;
[B,FitInfo] = lasso(X, y, "Weights", w)

Expected output:

Rows with larger weights contribute more to the weighted least-squares objective.

Using lasso with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how lasso changes the result.

Run a small lasso example, explain the result, then change one input and compare the output.

FAQ

Where is the intercept stored?⌄

The coefficient matrix B contains only predictor coefficients. Intercepts are returned in FitInfo.Intercept, one value per Lambda.

Does RunMat implement covariance-matrix acceleration?⌄

No. RunMat accepts UseCovariance for script compatibility, but fitting uses the direct coordinate-descent path and FitInfo.UseCovariance is false.

How are Lambda values ordered?⌄

RunMat returns Lambda values in ascending order in FitInfo.Lambda, and the columns of B use the same order.

Does cross-validation match MATLAB's random partitions exactly?⌄

No. RunMat currently uses deterministic round-robin K-fold partitions. The returned fields and selection semantics are MATLAB-compatible, but fold assignment is deterministic.

Related Stats functions

Ml

bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne

Summary

binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv

Random

binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd

Hist

histc · histcounts · histcounts2

Options

statget · statset

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how lasso is executed, line by line, in Rust.

  • View the source for lasso in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How lasso works
  • Examples
  • Fit a sparse linear model for an explicit Lambda
  • Return FitInfo for an elastic-net path
  • Use K-fold cross-validation
  • Weight observations
  • Using lasso with coding agents
  • FAQ
  • Related Stats functions
  • Ml
  • Summary
  • Random
  • Hist
  • Options
  • Open-source implementation
  • About RunMat