NMath User's Guide

42.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

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

Code Example – VB linear regression

```Dim Predictors As New DoubleVector(150.0, 33.5, 0.66, 80.0)
```
```Dim Predicted As Double = 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

```var 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 );
```

Code Example – VB linear regression

```Dim Predictors As 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 ]")
```
```Dim Predicted As DoubleVector =
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