NMath Stats User's Guide

TOC | Previous | Next | Index

6.3 Predictions (.NET, C#, CSharp, VB, Visual Basic, F#)

You can use a LinearRegression object to generate predictions. The PredictedObservation() method returns the response predicted by the model for a given set of predictor variable values. For example:

Code Example – C# linear regression

DoubleVector predictors =
  new DoubleVector( 150.0, 33.5, 0.66, 80.0 );
double predicted = lr.PredictedObservation( predictors );

A MismatchedSizeException is raised if the length of the given vector is not equal to the number of parameters in the model.

Similarly, the PredictedObservations() method returns the responses predicted by the model for a given collection of predictors:

Code Example – C# linear regression

DoubleMatrix predictors =
  new DoubleMatrix( "3x4 [ 150.0 33.5 0.66 80.0 
                           160.0 24.5 0.88 70.0 
                           170.0 22.6 0.56 60.0 ]" );
DoubleVector predicted = lr.PredictedObservations( predictors );

In the returned vector of predicted observations, the ith element is the predicted response for the set of predictor variable values in the ith row of the given matrix.


Top

Top