MLPACK  1.0.11
linear_regression.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_METHODS_LINEAR_REGRESSION_LINEAR_REGRESSION_HPP
24 #define __MLPACK_METHODS_LINEAR_REGRESSION_LINEAR_REGRESSION_HPP
25 
26 #include <mlpack/core.hpp>
27 
28 namespace mlpack {
29 namespace regression {
30 
37 {
38  public:
47  LinearRegression(const arma::mat& predictors,
48  const arma::vec& responses,
49  const double lambda = 0,
50  const bool intercept = true,
51  const arma::vec& weights = arma::vec()
52  );
53 
59  LinearRegression(const std::string& filename);
60 
66  LinearRegression(const LinearRegression& linearRegression);
67 
72 
79  void Predict(const arma::mat& points, arma::vec& predictions) const;
80 
98  double ComputeError(const arma::mat& points,
99  const arma::vec& responses) const;
100 
102  const arma::vec& Parameters() const { return parameters; }
104  arma::vec& Parameters() { return parameters; }
105 
107  double Lambda() const { return lambda; }
109  double& Lambda() { return lambda; }
110 
111  // Returns a string representation of this object.
112  std::string ToString() const;
113 
114  private:
119  arma::vec parameters;
124  double lambda;
126  bool intercept;
127 };
128 
129 }; // namespace linear_regression
130 }; // namespace mlpack
131 
132 #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:31
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).