mlpack::regression::LinearRegression(3) A simple linear regression algorithm using ordinary least squares.

SYNOPSIS


Public Member Functions


LinearRegression (const arma::mat &predictors, const arma::vec &responses, const double lambda=0)
Creates the model.
LinearRegression (const std::string &filename)
Initialize the model from a file.
LinearRegression (const LinearRegression &linearRegression)
Copy constructor.
LinearRegression ()
Empty constructor.
double ComputeError (const arma::mat &points, const arma::vec &responses) const
Calculate the L2 squared error on the given predictors and responses using this linear regression model.
double Lambda () const
Return the Tikhonov regularization parameter for ridge regression.
double & Lambda ()
Modify the Tikhonov regularization parameter for ridge regression.
const arma::vec & Parameters () const
Return the parameters (the b vector).
arma::vec & Parameters ()
Modify the parameters (the b vector).
void Predict (const arma::mat &points, arma::vec &predictions) const
Calculate y_i for each data point in points.
std::string ToString () const

Private Attributes


double lambda
The Tikhonov regularization parameter for ridge regression (0 for linear regression).
arma::vec parameters
The calculated B.

Detailed Description

A simple linear regression algorithm using ordinary least squares.

Optionally, this class can perform ridge regression, if the lambda parameter is set to a number greater than zero.

Definition at line 35 of file linear_regression.hpp.

Constructor & Destructor Documentation

mlpack::regression::LinearRegression::LinearRegression (const arma::mat &predictors, const arma::vec &responses, const doublelambda = 0)

Creates the model.

Parameters:

predictors X, matrix of data points to create B with.
responses y, the measured data for each point in X

mlpack::regression::LinearRegression::LinearRegression (const std::string &filename)

Initialize the model from a file.

Parameters:

filename the name of the file to load the model from.

mlpack::regression::LinearRegression::LinearRegression (const LinearRegression &linearRegression)

Copy constructor.

Parameters:

linearRegression the other instance to copy parameters from.

mlpack::regression::LinearRegression::LinearRegression () [inline]

Empty constructor.

Definition at line 65 of file linear_regression.hpp.

Member Function Documentation

double mlpack::regression::LinearRegression::ComputeError (const arma::mat &points, const arma::vec &responses) const

Calculate the L2 squared error on the given predictors and responses using this linear regression model. This calculation returns

\.PP where $ y $ is the responses vector, $ X $ is the matrix of predictors, and $ B $ is the parameters of the trained linear regression model.

As this number decreases to 0, the linear regression fit is better.

Parameters:

predictors Matrix of predictors (X).
responses Vector of responses (y).

double mlpack::regression::LinearRegression::Lambda () const [inline]

Return the Tikhonov regularization parameter for ridge regression.

Definition at line 101 of file linear_regression.hpp.

References lambda.

double& mlpack::regression::LinearRegression::Lambda () [inline]

Modify the Tikhonov regularization parameter for ridge regression.

Definition at line 103 of file linear_regression.hpp.

References lambda.

const arma::vec& mlpack::regression::LinearRegression::Parameters () const [inline]

Return the parameters (the b vector).

Definition at line 96 of file linear_regression.hpp.

References parameters.

arma::vec& mlpack::regression::LinearRegression::Parameters () [inline]

Modify the parameters (the b vector).

Definition at line 98 of file linear_regression.hpp.

References parameters.

void mlpack::regression::LinearRegression::Predict (const arma::mat &points, arma::vec &predictions) const

Calculate y_i for each data point in points.

Parameters:

points the data points to calculate with.
predictions y, will contain calculated values on completion.

std::string mlpack::regression::LinearRegression::ToString () const

Member Data Documentation

double mlpack::regression::LinearRegression::lambda [private]

The Tikhonov regularization parameter for ridge regression (0 for linear regression).

Definition at line 119 of file linear_regression.hpp.

Referenced by Lambda().

arma::vec mlpack::regression::LinearRegression::parameters [private]

The calculated B. Initialized and filled by constructor to hold the least squares solution.

Definition at line 113 of file linear_regression.hpp.

Referenced by Parameters().

Author

Generated automatically by Doxygen for MLPACK from the source code.