mlpack
2.2.5
|
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 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... | |
bool | Intercept () const |
Return whether or not an intercept term is used in the 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... | |
template<typename Archive > | |
void | Serialize (Archive &ar, const unsigned int) |
Serialize the model. More... | |
void | Train (const arma::mat &predictors, const arma::vec &responses, const bool intercept=true, const arma::vec &weights=arma::vec()) |
Train the LinearRegression model on the given data. 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 26 of file linear_regression.hpp.
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. |
lambda | Regularization constant for ridge regression. |
intercept | Whether or not to include an intercept term. |
weights | Observation weights (for boosting). |
LinearRegression | ( | const LinearRegression & | linearRegression | ) |
Copy constructor.
linearRegression | the other instance to copy parameters from. |
|
inline |
Empty constructor.
This gives a non-working model, so make sure Train() is called (or make sure the model parameters are set) before calling Predict()!
Definition at line 56 of file linear_regression.hpp.
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.
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.
points | Matrix of predictors (X). |
responses | Vector of responses (y). |
Referenced by RegressionDistribution::RegressionDistribution().
|
inline |
Return whether or not an intercept term is used in the model.
Definition at line 114 of file linear_regression.hpp.
|
inline |
Return the Tikhonov regularization parameter for ridge regression.
Definition at line 109 of file linear_regression.hpp.
|
inline |
Modify the Tikhonov regularization parameter for ridge regression.
Definition at line 111 of file linear_regression.hpp.
|
inline |
Return the parameters (the b vector).
Definition at line 104 of file linear_regression.hpp.
Referenced by RegressionDistribution::Dimensionality(), and RegressionDistribution::Parameters().
|
inline |
Modify the parameters (the b vector).
Definition at line 106 of file linear_regression.hpp.
void 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. |
|
inline |
Serialize the model.
Definition at line 120 of file linear_regression.hpp.
References mlpack::data::CreateNVP().
void Train | ( | const arma::mat & | predictors, |
const arma::vec & | responses, | ||
const bool | intercept = true , |
||
const arma::vec & | weights = arma::vec() |
||
) |
Train the LinearRegression model on the given data.
Careful! This will completely ignore and overwrite the existing model. This particular implementation does not have an incremental training algorithm. To set the regularization parameter lambda, call Lambda() or set a different value in the constructor.
predictors | X, the matrix of data points to train the model on. |
responses | y, the vector of responses to each data point. |
intercept | Whether or not to fit an intercept term. |
weights | Observation weights (for boosting). |