---
title: "Lasso Regression in JavaScript with @kanaries/ml"
description: "Use the LassoRegression JavaScript and TypeScript implementation in @kanaries/ml for sparse regularized linear regression in browser and Node.js workflows."
canonical_url: "https://ml.kanaries.net/docs/apis/linear/lassoRegression"
markdown_url: "https://ml.kanaries.net/docs/apis/linear/lassoRegression.md"
---
# Lasso Regression in JavaScript

## Algorithm overview

Lasso regression uses L1 regularization, which can shrink some coefficients to zero. It is useful when you want a linear model that can perform simple feature selection while controlling overfitting.

## JavaScript implementation

`@kanaries/ml` implements `Linear.LassoRegression` with coordinate-descent style optimization and a JavaScript API for browser or Node.js applications.

## Interactive Lasso regression playground

Change the L1 penalty, dataset, and noise to see how regularization changes the fitted trend. The model is trained live with `Linear.LassoRegression` in your browser.

> The HTML version includes an interactive Lasso Regression playground powered by @kanaries/ml. You can change the dataset, noise, and model controls; add observations; and inspect live predictions plus train and holdout metrics. The runnable guide and API reference continue below. [Open the HTML page](https://ml.kanaries.net/docs/apis/linear/lassoRegression).

## Quick start example

```ts
import { Linear } from '@kanaries/ml';

const X = [[0, 1], [1, 1], [2, 0], [3, 0]];
const y = [1, 2, 3, 4];

const model = new Linear.LassoRegression({ alpha: 0.1, maxIter: 1000, tol: 1e-6 });
model.fit(X, y);
const pred = model.predict([[4, 0]]);
console.log(pred);
```

## Detailed API reference

```ts
new Linear.LassoRegression(props?: {
  alpha?: number;
  fitIntercept?: boolean;
  maxIter?: number;
  tol?: number;
})
```

Options:

- `alpha?: number`, default `1`. L1 penalty strength.
- `fitIntercept?: boolean`, default `true`.
- `maxIter?: number`, default `1000`.
- `tol?: number`, default `1e-6`.

Methods:

- `fit(X: number[][], Y: number[]): void`
- `predict(X: number[][]): number[]`

## sklearn-style alias: `Lasso`

`Linear.Lasso` extends `Linear.LassoRegression` with identical options and methods. Use it when you prefer the scikit-learn class name:

```ts
import { Linear } from '@kanaries/ml';

const model = new Linear.Lasso({ alpha: 0.1, fitIntercept: true });
model.fit([[0, 1], [1, 1], [2, 0]], [1, 2, 3]);
const pred = model.predict([[3, 0]]);
```
