NMath User's Guide

43.3 Checking for Convergence (.NET, C#, CSharp, VB, Visual Basic, F#)

After constructing a LogisticRegression object, first check that the parameter calculation was successful. For example, this code checks the IsGood property, and if the calculation failed, prints out some diagnostic information using the ParameterCalculationErrorMessage property.

Code Example – C# logistic regression

```if ( !lr.IsGood )
```
```{
```
```    Console.WriteLine(
```
```      "Logistic regression parameter calculation failed:" );
```
```    Console.WriteLine( lr.ParameterCalculationErrorMessage );

```

```    var parameterCalc = lr.ParameterCalculator;
```
```    Console.WriteLine( "Maximum iterations: " +
```
```      parameterCalc.MaxIterations );
```
```    Console.WriteLine( "Number of iterations: " +
```
```      parameterCalc.Iterations );
```
```    Console.WriteLine( "Converged? " + parameterCalc.Converged );
```
```}
```

Code Example – VB logistic regression

```If Not LR.IsGood Then
```
```  Console.WriteLine("Logistic regression parameter calculation
```
```    failed:")
```
```  Console.WriteLine(LR.ParameterCalculationErrorMessage)

```

```  Dim ParameterCalc As ParameterCalc = LR.ParameterCalculator
```
```  Console.WriteLine("Maximum iterations: " &
```
```    ParameterCalc.MaxIterations)
```
```  Console.WriteLine("Number of iterations: " &
```
```    ParameterCalc.Iterations)
```
```  Console.WriteLine("Converged? " & ParameterCalc.Converged)
```
```End If
```

Top

Top