[mlpack-svn] r11515 - mlpack/trunk/doc/tutorials/linear_regression

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Feb 14 14:13:59 EST 2012


Author: jcline3
Date: 2012-02-14 14:13:58 -0500 (Tue, 14 Feb 2012)
New Revision: 11515

Modified:
   mlpack/trunk/doc/tutorials/linear_regression/linear_regression.txt
Log:
coding with LinearRegression examples

Modified: mlpack/trunk/doc/tutorials/linear_regression/linear_regression.txt
===================================================================
--- mlpack/trunk/doc/tutorials/linear_regression/linear_regression.txt	2012-02-14 17:00:05 UTC (rev 11514)
+++ mlpack/trunk/doc/tutorials/linear_regression/linear_regression.txt	2012-02-14 19:13:58 UTC (rev 11515)
@@ -34,6 +34,7 @@
    - \ref linreg_ex1
    - \ref linreg_ex2
    - \ref linreg_ex3
+   - \ref linreg_ex4
  - \ref further_doc
 
 @section cli Command-Line 'linear_regression'
@@ -211,6 +212,60 @@
 predictions, will be modified to contain the predicted values corresponding to
 each row of the points matrix.
 
+ at subsection linreg_ex1 Generating a model
+
+ at code
+#include <mlpack/methods/linear_regression/linear_regression.hpp>
+
+using namespace::regression
+
+arma::mat data; // The dataset itself
+arma::vec responses; // The responses, one row for each row in data
+
+// Regress
+LinearRegression lr(data,responses);
+
+// Get the parameters, or coefficients
+arma vec parameters = lr.Parameters();
+ at endcode
+
+ at subsection linreg_ex2 Setting a model
+Assuming you already have a model and do not need to create one, this is how
+you would set the parameters for a LinearRegression instance.
+
+ at code
+arma::vec parameters; // Your model
+
+LinearRegression lr(); // Create a new LinearRegression instance or reuse one
+lr.Parameters() = parameters; // Set the model
+ at endcode
+
+ at subsection linreg_ex3 Load a model from a file
+If you have a generated model in a file somewhere you would like to load and use,
+you can simply pass it to the LinearRegression initializer like so.
+
+ at code
+std::string filename; // The path and name of your file
+
+LinearRegression lr(filename); // Will load the model internally
+ at endcode
+
+ at subsection linreg_ex4 Prediction
+Once you have generated or loaded a model using one of the aforementioned methods,
+you can predict values for a dataset.
+
+ at code
+
+LinearRegression lr();
+// Load or generate your model
+
+arma::mat points; // The dataset we want to predict on, each row is a data point
+arma::vec predictions; // This will store the predictions, one row for each point
+
+lr.Predict(points, predictions); // Predict
+// Now, predictions will contain the predicted values.
+ at endcode
+
 @subsection further_doc Further documentation
 
 For further documentation on the LinearRegression class, consult the




More information about the mlpack-svn mailing list