Simple Linear Regression and Prediction

>>> from mlpack import linear_regression

An implementation of simple linear regression and simple ridge regression using ordinary least squares. This solves the problem

y = X * b + e

where X (specified by 'training') and y (specified either as the last column of the input matrix 'training' or via the 'training_responses' parameter) are known and b is the desired variable. If the covariance matrix (X'X) is not invertible, or if the solution is overdetermined, then specify a Tikhonov regularization constant (with 'lambda_') greater than 0, which will regularize the covariance matrix to make it invertible. The calculated b may be saved with the 'output_predictions' output parameter.

Optionally, the calculated value of b is used to predict the responses for another matrix X' (specified by the 'test' parameter):

y' = X' * b

and the predicted responses y' may be saved with the 'output_predictions' output parameter. This type of regression is related to least-angle regression, which mlpack implements as the 'lars' program.

For example, to run a linear regression on the dataset 'X' with responses 'y', saving the trained model to 'lr_model', the following command could be used:

>>> output = linear_regression(training=X, training_responses=y)
>>> lr_model = output['output_model']

Then, to use 'lr_model' to predict responses for a test set 'X_test', saving the predictions to 'X_test_responses', the following command could be used:

>>> output = linear_regression(input_model=lr_model, test=X_test)
>>> X_test_responses = output['output_predictions']

input options

output options

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