[mlpack-svn] r15850 - mlpack/trunk/src/mlpack/methods/linear_regression
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Sep 26 15:58:32 EDT 2013
Author: rcurtin
Date: Thu Sep 26 15:58:32 2013
New Revision: 15850
Log:
Add --lambda option to linear_regression.
Modified:
mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp
Modified: mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp (original)
+++ mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp Thu Sep 26 15:58:32 2013
@@ -7,19 +7,23 @@
#include <mlpack/core.hpp>
#include "linear_regression.hpp"
-PROGRAM_INFO("Simple Linear Regression Prediction",
- "An implementation of simple linear regression using ordinary least "
- "squares. This solves the problem\n\n"
+PROGRAM_INFO("Simple Linear Regression and Prediction",
+ "An implementation of simple linear regression and simple ridge regression "
+ "using ordinary least squares. This solves the problem\n\n"
" y = X * b + e\n\n"
"where X (--input_file) and y (the last row of --input_file, or "
- "--input_responses) are known and b is the desired variable. The "
- "calculated b is saved to disk (--output_file).\n"
+ "--input_responses) are known and b is the desired variable. If the "
+ "covariance matrix (X'X) is not invertible, or if the solution is "
+ "overdetermined, then specify a Tikhonov regularization constant (--lambda)"
+ " greater than 0, which will regularize the covariance matrix to make it "
+ "invertible. The calculated b is saved to disk (--output_file).\n"
"\n"
"Optionally, the calculated value of b is used to predict the responses for"
" another matrix X' (--test_file):\n\n"
" y' = X' * b\n\n"
"and these predicted responses, y', are saved to a file "
- "(--output_predictions).");
+ "(--output_predictions). This type of regression is related to least-angle"
+ " regression, which mlpack implements with the 'lars' executable.");
PARAM_STRING("input_file", "File containing X (regressors).", "i", "");
PARAM_STRING("input_responses", "Optional file containing y (responses). If "
@@ -36,6 +40,9 @@
PARAM_STRING("output_predictions", "If --test_file is specified, this file is "
"where the predicted responses will be saved.", "p", "predictions.csv");
+PARAM_DOUBLE("lambda", "Tikhonov regularization for ridge regression. If 0, "
+ "the method reduces to linear regression.", "l", 0.0);
+
using namespace mlpack;
using namespace mlpack::regression;
using namespace arma;
@@ -52,11 +59,13 @@
const string responseName = CLI::GetParam<string>("input_responses");
const string testName = CLI::GetParam<string>("test_file");
const string trainName = CLI::GetParam<string>("input_file");
+ const double lambda = CLI::GetParam<double>("lambda");
mat regressors;
mat responses;
LinearRegression lr;
+ lr.Lambda() = lambda;
bool computeModel = false;
More information about the mlpack-svn
mailing list