Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
GH-60: Regularization breaks LogisticRegressionAnalysis in 2.14.0
Browse files Browse the repository at this point in the history
Correcting logistic regression regularization and adding more unit tests.
  • Loading branch information
cesarsouza committed Feb 7, 2015
1 parent 9b399de commit 3cba330
Show file tree
Hide file tree
Showing 9 changed files with 1,140 additions and 870 deletions.
25 changes: 22 additions & 3 deletions Sources/Accord.Statistics/Analysis/LogisticRegressionAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public class LogisticRegressionAnalysis : IRegressionAnalysis
private string outputName;

private double[,] sourceMatrix;
private double[] result;
private double[] result;

double regularization = 1e-10;

private LogisticCoefficientCollection coefficientCollection;

Expand All @@ -176,6 +178,7 @@ public LogisticRegressionAnalysis(double[][] inputs, double[] outputs)
// Initial argument checking
if (inputs == null)
throw new ArgumentNullException("inputs");

if (outputs == null)
throw new ArgumentNullException("outputs");

Expand Down Expand Up @@ -264,6 +267,18 @@ public double Tolerance
{
get { return tolerance; }
set { tolerance = value; }
}

/// <summary>
/// Gets or sets the regularization value to be
/// added in the objective function. Default is
/// 1e-10.
/// </summary>
///
public double Regularization
{
get { return regularization; }
set { regularization = value; }
}

/// <summary>
Expand Down Expand Up @@ -537,7 +552,9 @@ private bool compute()
double delta;
int iteration = 0;

var learning = new IterativeReweightedLeastSquares(regression);
var learning = new IterativeReweightedLeastSquares(regression);

learning.Regularization = regularization;

do // learning iterations until convergence
{
Expand All @@ -564,7 +581,9 @@ private void computeInner()

// Perform likelihood-ratio tests against diminished nested models
var innerModel = new LogisticRegression(inputCount - 1);
var learning = new IterativeReweightedLeastSquares(innerModel);
var learning = new IterativeReweightedLeastSquares(innerModel);

learning.Regularization = regularization;

for (int i = 0; i < inputCount; i++)
{
Expand Down
Loading

0 comments on commit 3cba330

Please sign in to comment.