MLPACK
1.0.11
|
A simple linear regression algorithm using ordinary least squares. More...
Public Member Functions | |
LinearRegression (const arma::mat &predictors, const arma::vec &responses, const double lambda=0, const bool intercept=true, const arma::vec &weights=arma::vec()) | |
Creates the model. More... | |
LinearRegression (const std::string &filename) | |
Initialize the model from a file. More... | |
LinearRegression (const LinearRegression &linearRegression) | |
Copy constructor. More... | |
LinearRegression () | |
Empty constructor. More... | |
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. More... | |
double | Lambda () const |
Return the Tikhonov regularization parameter for ridge regression. More... | |
double & | Lambda () |
Modify the Tikhonov regularization parameter for ridge regression. More... | |
const arma::vec & | Parameters () const |
Return the parameters (the b vector). More... | |
arma::vec & | Parameters () |
Modify the parameters (the b vector). More... | |
void | Predict (const arma::mat &points, arma::vec &predictions) const |
Calculate y_i for each data point in points. More... | |
std::string | ToString () const |
Private Attributes | |
bool | intercept |
Indicates whether first parameter is intercept. More... | |
double | lambda |
The Tikhonov regularization parameter for ridge regression (0 for linear regression). More... | |
arma::vec | parameters |
The calculated B. More... | |
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 36 of file linear_regression.hpp.
mlpack::regression::LinearRegression::LinearRegression | ( | const arma::mat & | predictors, |
const arma::vec & | responses, | ||
const double | lambda = 0 , |
||
const bool | intercept = true , |
||
const arma::vec & | weights = arma::vec() |
||
) |
Creates the model.
predictors | X, matrix of data points to create B with. |
responses | y, the measured data for each point in X |
intercept | include intercept? |
weights | observation weights |
mlpack::regression::LinearRegression::LinearRegression | ( | const std::string & | filename | ) |
Initialize the model from a file.
filename | the name of the file to load the model from. |
mlpack::regression::LinearRegression::LinearRegression | ( | const LinearRegression & | linearRegression | ) |
Copy constructor.
linearRegression | the other instance to copy parameters from. |
|
inline |
Empty constructor.
Definition at line 71 of file linear_regression.hpp.
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
where is the responses vector,
is the matrix of predictors, and
is the parameters of the trained linear regression model.
As this number decreases to 0, the linear regression fit is better.
predictors | Matrix of predictors (X). |
responses | Vector of responses (y). |
|
inline |
Return the Tikhonov regularization parameter for ridge regression.
Definition at line 107 of file linear_regression.hpp.
References lambda.
|
inline |
Modify the Tikhonov regularization parameter for ridge regression.
Definition at line 109 of file linear_regression.hpp.
References lambda.
|
inline |
Return the parameters (the b vector).
Definition at line 102 of file linear_regression.hpp.
References parameters.
|
inline |
Modify the parameters (the b vector).
Definition at line 104 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.
points | the data points to calculate with. |
predictions | y, will contain calculated values on completion. |
std::string mlpack::regression::LinearRegression::ToString | ( | ) | const |
|
private |
Indicates whether first parameter is intercept.
Definition at line 126 of file linear_regression.hpp.
|
private |
The Tikhonov regularization parameter for ridge regression (0 for linear regression).
Definition at line 124 of file linear_regression.hpp.
Referenced by Lambda().
|
private |
The calculated B.
Initialized and filled by constructor to hold the least squares solution.
Definition at line 119 of file linear_regression.hpp.
Referenced by Parameters().