mlpack  1.0.12
linear_regression.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_LINEAR_REGRESSION_LINEAR_REGRESSION_HPP
16 #define __MLPACK_METHODS_LINEAR_REGRESSION_LINEAR_REGRESSION_HPP
17 
18 #include <mlpack/core.hpp>
19 
20 namespace mlpack {
21 namespace regression {
22 
29 {
30  public:
39  LinearRegression(const arma::mat& predictors,
40  const arma::vec& responses,
41  const double lambda = 0,
42  const bool intercept = true,
43  const arma::vec& weights = arma::vec()
44  );
45 
51  LinearRegression(const std::string& filename);
52 
58  LinearRegression(const LinearRegression& linearRegression);
59 
64 
71  void Predict(const arma::mat& points, arma::vec& predictions) const;
72 
90  double ComputeError(const arma::mat& points,
91  const arma::vec& responses) const;
92 
94  const arma::vec& Parameters() const { return parameters; }
96  arma::vec& Parameters() { return parameters; }
97 
99  double Lambda() const { return lambda; }
101  double& Lambda() { return lambda; }
102 
103  // Returns a string representation of this object.
104  std::string ToString() const;
105 
106  private:
111  arma::vec parameters;
116  double lambda;
118  bool intercept;
119 };
120 
121 }; // namespace linear_regression
122 }; // namespace mlpack
123 
124 #endif // __MLPACK_METHODS_LINEAR_REGRESSCLIN_HPP
void Predict(const arma::mat &points, arma::vec &predictions) const
Calculate y_i for each data point in points.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
A simple linear regression algorithm using ordinary least squares.
bool intercept
Indicates whether first parameter is intercept.
double & Lambda()
Modify the Tikhonov regularization parameter for ridge regression.
arma::vec parameters
The calculated B.
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 mod...
double Lambda() const
Return the Tikhonov regularization parameter for ridge regression.
double lambda
The Tikhonov regularization parameter for ridge regression (0 for linear regression).
const arma::vec & Parameters() const
Return the parameters (the b vector).
arma::vec & Parameters()
Modify the parameters (the b vector).