compute-io/lasso-regression

语言: JavaScript

git: https://github.com/compute-io/lasso-regression

LASSO回归(带有L1惩罚的正则化回归)。
LASSO regression (regularized regression with L1 penalty).
README.md (中文)

LASSO回归

NPM version Build Status Coverage Status Dependencies

使用L1惩罚执行正则化最小二乘回归。

给定响应变量Y和预测变量X的矢量,将线性回归模型定义为


其中beta_0是截距系数,beta是预测系数的矢量。给定数据点(x_1,y_1),...,(x_N,y_N),该包使用LASSO估计回归系数。这个L1惩罚回归惩罚非零系数,并通过解决以下问题获得其拟合:


lambda参数确定放置在β矢量的L1范数上的惩罚的大小。 L1范数定义为


当lambda = 0时,问题会减少到多元线性回归,而lambda - >∞将导致仅限拦截模型。

正如我们所观察到的,对于非零惩罚,LASSO将系数估计值缩减为零,这使得LASSO执行模型选择:增加lambda,在解释Y时没有太大贡献的预测变量将倾向于从模型中移除。

安装

$ npm install compute-lasso-regression

要在浏览器中使用,请使用browserify。

用法

var lasso = require( 'compute-lasso-regression' );

套索(x,y,lambda)

适合输入x和y的正则化回归。 x应该是具有N行和p列的矩阵,每行代表一个观察,每列代表一个预测变量。 y必须是N个响应值的数组或类型数组。

参考

  • Tibshirani,R。(1994)。通过套索进行回归选择和收缩。皇家统计学会杂志B. doi:10.2307 / 2346178
  • Friedman,J.,Hastie,T。,&Tibshirani,R。(2010)。基于坐标下降的广义线性模型的正则化路径。统计软件期刊,33(1),1-22。 DOI:10.1359 / JBMR.0301229

例子

var lasso = require( 'compute-lasso-regression' ),
    randomNormal = require( 'distributions-normal-random' ),
    x, y,
    out,
    i;

// Set seed of random number generator:
randomNormal.seed = 117;

// Create a 100 x 10 matrix of standard normal variates
x = randomNormal( [100,10], {
    'dtype':'float64'
});

// Generate response variables
y = new Float64Array( 100 );
for ( i = 0; i < y.length; i++ ) {
    y[ i ] = 4 * x.get( i, 3 ) +
        2 * x.get( i, 5 ) -
        4 * x.get( i, 7 ) -
        2 * x.get( i, 9 ) +
        randomNormal();
}

out = lasso( x, y, 0.4 );

要从顶级应用程序目录运行示例代码,

$ node ./examples/index.js

测试

单元

单元测试使用带有Chai断言的Mocha测试框架。要运行测试,请在顶级应用程序目录中执行以下命令:

$ make test

所有新功能开发都应该有相应的单元测试来验证正确的功能。

测试覆盖率

该存储库使用Istanbul作为其代码覆盖工具。要生成测试覆盖率报告,请在顶级应用程序目录中执行以下命令:

$ make test-cov

伊斯坦布尔创建了一个./reports/coverage目录。要访问报告的HTML版本,

$ make view-cov

执照

有许可证。

版权

版权所有©2015。Compute.io作者。

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

LASSO Regression

NPM version Build Status Coverage Status Dependencies

Performs regularized least-squares regression with L1 penalty.

Given a response variable Y and a vector of predictors X, a linear regression model is defined as


where beta_0 is the intercept coefficient and beta a vector of predictor coefficients. Given data points (x_1,y_1),...,(x_N,y_N), this package estimates the regression coefficients using the LASSO. This L1 penalized regression penalizes non-zero coefficients and its fit is obtained by solving the following problem:


The lambda parameter determines the size of the penalty placed on the L1 norm of the beta vector. The L1 norm is defined as


When lambda = 0, the problem reduces to multiple linear regression, whereas lambda -> ∞ will result in an intercept-only model.

As we observe, for non-zero penalties the LASSO shrinks coefficient estimates to zero, which makes the LASSO perform model selection: Increasing lambda, predictors that do not contribute much in explaining Y will tend to get removed from the model.

Installation

$ npm install compute-lasso-regression

For use in the browser, use browserify.

Usage

var lasso = require( 'compute-lasso-regression' );

lasso( x, y, lambda )

Fits a regularized regression for inputs x and y. x is expected to be a matrix with N rows and p columns, each row representing one observation and each column one predictor variable. y has to be an array or typed array of N response values.

References

  • Tibshirani, R. (1994). Regression Selection and Shrinkage via the Lasso. Journal of the Royal Statistical Society B. doi:10.2307/2346178

  • Friedman, J., Hastie, T., & Tibshirani, R. (2010). Regularization Paths for Generalized Linear Models via Coordinate Descent. Journal of Statistical Software, 33(1), 1–22. doi:10.1359/JBMR.0301229

Examples

var lasso = require( 'compute-lasso-regression' ),
    randomNormal = require( 'distributions-normal-random' ),
    x, y,
    out,
    i;

// Set seed of random number generator:
randomNormal.seed = 117;

// Create a 100 x 10 matrix of standard normal variates
x = randomNormal( [100,10], {
    'dtype':'float64'
});

// Generate response variables
y = new Float64Array( 100 );
for ( i = 0; i < y.length; i++ ) {
    y[ i ] = 4 * x.get( i, 3 ) +
        2 * x.get( i, 5 ) -
        4 * x.get( i, 7 ) -
        2 * x.get( i, 9 ) +
        randomNormal();
}

out = lasso( x, y, 0.4 );

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

Copyright

Copyright © 2015. The Compute.io Authors.