mlpack.lars

lars(...)LARS

>>> from mlpack import lars

An implementation of LARS: Least Angle Regression (Stagewise/laSso). This is a stage-wise homotopy-based algorithm for L1-regularized linear regression (LASSO) and L1+L2-regularized linear regression (Elastic Net).

This program is able to train a LARS/LASSO/Elastic Net model or load a model from file, output regression predictions for a test set, and save the trained model to a file. The LARS algorithm is described in more detail below:

Let X be a matrix where each row is a point and each column is a dimension, and let y be a vector of targets.

The Elastic Net problem is to solve

min_beta 0.5 || X * beta - y ||_2^2 + lambda_1 ||beta||_1 +

0.5 lambda_2 ||beta||_2^2

If lambda1 > 0 and lambda2 = 0, the problem is the LASSO.

If lambda1 > 0 and lambda2 > 0, the problem is the Elastic Net.

If lambda1 = 0 and lambda2 > 0, the problem is ridge regression.

If lambda1 = 0 and lambda2 = 0, the problem is unregularized linear regression.

For efficiency reasons, it is not recommended to use this algorithm with 'lambda1' = 0. In that case, use the 'linear_regression' program, which implements both unregularized linear regression and ridge regression.

To train a LARS/LASSO/Elastic Net model, the 'input' and 'responses' parameters must be given. The 'lambda1', 'lambda2', and 'use_cholesky' parameters control the training options. A trained model can be saved with the 'output_model'. If no training is desired at all, a model can be passed via the 'input_model' parameter.

The program can also provide predictions for test data using either the trained model or the given input model. Test points can be specified with the 'test' parameter. Predicted responses to the test points can be saved with the 'output_predictions' output parameter.

For example, the following command trains a model on the data 'data' and responses 'responses' with lambda1 set to 0.4 and lambda2 set to 0 (so, LASSO is being solved), and then the model is saved to 'lasso_model':

>>> output = lars(input=data, responses=responses, lambda1=0.4, lambda2=0)

>>> lasso_model = output['output_model']

The following command uses the 'lasso_model' to provide predicted responses for the data 'test' and save those responses to 'test_predictions':

>>> output = lars(input_model=lasso_model, test=test)

>>> test_predictions = output['output_predictions']

## input options

- copy_all_inputs (bool): If specified, all input parameters will be deep copied before the method is run. This is useful for debugging problems where the input parameters are being modified by the algorithm, but can slow down the code.
- input (numpy matrix or arraylike, float dtype): Matrix of covariates (X).
- input_model (mlpack.LARSType): Trained LARS model to use.
- lambda1 (float): Regularization parameter for l1-norm penalty. Default value 0.
- lambda2 (float): Regularization parameter for l2-norm penalty. Default value 0.
- responses (numpy matrix or arraylike, float dtype): Matrix of responses/observations (y).
- test (numpy matrix or arraylike, float dtype): Matrix containing points to regress on (test points).
- use_cholesky (bool): Use Cholesky decomposition during computation rather than explicitly computing the full Gram matrix.
- verbose (bool): Display informational messages and the full list of parameters and timers at the end of execution.

## output options

The return value from the binding is a dict containing the following elements:

- output_model (mlpack.LARSType): Output LARS model.
- output_predictions (numpy matrix, float dtype): If --test_file is specified, this file is where the predicted responses will be saved.