Lasso Regression
Use the LassoRegression JavaScript and TypeScript implementation in @kanaries/ml for sparse regularized linear regression in browser and Node.js workflows.
View as MarkdownAlgorithm 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.
LassoRegression playground
Adjust the data and model, then click the chart to add a training observation.
Quick start example
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
new Linear.LassoRegression(props?: {
alpha?: number;
fitIntercept?: boolean;
maxIter?: number;
tol?: number;
})Options:
alpha?: number, default1. L1 penalty strength.fitIntercept?: boolean, defaulttrue.maxIter?: number, default1000.tol?: number, default1e-6.
Methods:
fit(X: number[][], Y: number[]): voidpredict(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:
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]]);Ridge Regression
Use the RidgeRegression JavaScript and TypeScript implementation in @kanaries/ml for regularized linear regression in browser and Node.js applications.
ElasticNet
Fit linear regression with combined L1 and L2 regularization using the ElasticNet JavaScript and TypeScript implementation in @kanaries/ml.