Click or drag to resize
Accord.NET (logo)

GeneralizedLinearRegression Class

Generalized Linear Model Regression.
Inheritance Hierarchy
SystemObject
  Accord.MachineLearningTransformBaseDouble, Boolean
    Accord.MachineLearningClassifierBaseDouble, Boolean
      Accord.MachineLearningBinaryClassifierBaseDouble
        Accord.MachineLearningBinaryScoreClassifierBaseDouble
          Accord.MachineLearningBinaryLikelihoodClassifierBaseDouble
            Accord.Statistics.Models.RegressionGeneralizedLinearRegression
              Accord.Statistics.Models.RegressionLogisticRegression

Namespace:  Accord.Statistics.Models.Regression
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class GeneralizedLinearRegression : BinaryLikelihoodClassifierBase<double[]>, 
	ICloneable
Request Example View Source

The GeneralizedLinearRegression type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCoefficients Obsolete.
Obsolete. For quick compatibility fixes in the short term, use GetCoefficient(Int32) and SetCoefficient(Int32, Double).
Public propertyInputs Obsolete.
Gets the number of inputs handled by this model.
Public propertyIntercept
Gets or sets the intercept term. This is always the first value of the Coefficients array.
Public propertyLinear
Gets the underlying linear regression.
Public propertyLink
Gets the link function used by this generalized linear model.
Public propertyNumberOfClasses
Gets the number of classes expected and recognized by the classifier.
(Inherited from ClassifierBaseTInput, TClasses.)
Public propertyNumberOfInputs
Gets the number of inputs accepted by the model.
(Overrides TransformBaseTInput, TOutputNumberOfInputs.)
Public propertyNumberOfOutputs
Gets the number of outputs generated by the model.
(Inherited from TransformBaseTInput, TOutput.)
Public propertyNumberOfParameters
Gets the number of parameters in this model (equals the NumberOfInputs + 1).
Public propertyStandardErrors
Gets the standard errors associated with each coefficient during the model estimation phase.
Public propertyWeights
Gets or sets the linear weights of the regression model. The intercept term is not stored in this vector, but is instead available through the Intercept property.
Top
Methods
  NameDescription
Public methodChiSquare(Double, Double)
The likelihood ratio test of the overall model, also called the model chi-square test.
Public methodChiSquare(Double, Double, Double)
The likelihood ratio test of the overall model, also called the model chi-square test.
Public methodClone
Creates a new GeneralizedLinearRegression that is a copy of the current instance.
Public methodCompute(Double) Obsolete.
Computes the model output for the given input vector.
Public methodCompute(Double) Obsolete.
Computes the model output for each of the given input vectors.
Public methodDecide(TInput)
Computes a class-label decision for a given input.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodDecide(TInput)
Computes class-label decisions for a given set of input vectors.
(Inherited from ClassifierBaseTInput, TClasses.)
Public methodDecide(TInput, Boolean)
Computes class-label decisions for the given input.
(Inherited from BinaryClassifierBaseTInput.)
Public methodDecide(TInput, Boolean)
Computes a class-label decision for a given input.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodStatic memberFromLogisticRegression Obsolete.
Creates a GeneralizedLinearRegression from a LogisticRegression object.
Public methodGetCoefficient
Gets a coefficient value, where 0 is the intercept term and the other coefficients are indexed starting at 1.
Public methodGetConfidenceInterval
Gets the confidence interval for an input point.
Public methodGetDegreesOfFreedom
Gets the degrees of freedom when fitting the regression.
Public methodGetDeviance(Double, Double)
Gets the Deviance for the model.
Public methodGetDeviance(Double, Double, Double)
Gets the Deviance for the model.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetLogLikelihood(Double, Double)
Gets the Log-Likelihood for the model.
Public methodGetLogLikelihood(Double, Double, Double)
Gets the Log-Likelihood for the model.
Public methodGetLogLikelihoodRatio(Double, Double, GeneralizedLinearRegression)
Gets the Log-Likelihood Ratio between two models.
Public methodGetLogLikelihoodRatio(Double, Double, Double, GeneralizedLinearRegression)
Gets the Log-Likelihood Ratio between two models.
Public methodGetPredictionInterval
Gets the prediction interval for an input point.
Public methodGetPredictionStandardError
Gets the standard error of the prediction for a particular input vector.
Public methodGetStandardError
Gets the standard error of the fit for a particular input vector.
Public methodGetStandardErrors
Gets the standard error for each coefficient.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetWaldTest
Gets the Wald Test for a given coefficient.
Public methodLogLikelihood(TInput)
Predicts a class label vector for the given input vector, returning the log-likelihood that the input vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihood(TInput)
Predicts a class label vector for the given input vector, returning the log-likelihood that the input vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihood(TInput, Boolean)
Predicts a class label vector for the given input vector, returning the log-likelihood that the input vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihood(TInput, Int32)
Predicts a class label for each input vector, returning the log-likelihood that each vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihood(Double, Double)
Predicts a class label vector for the given input vectors, returning the log-likelihood that the input vector belongs to its predicted class.
(Overrides BinaryLikelihoodClassifierBaseTInputLogLikelihood(TInput, Double).)
Public methodLogLikelihood(TInput, Boolean, Double)
Predicts a class label for each input vector, returning the log-likelihood that each vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput)
Computes the log-likelihood that the given input vector belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput)
Computes the log-likelihoods that the given input vectors belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput, Boolean)
Predicts a class label vector for the given input vector, returning the log-likelihoods of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput, Double)
Computes the log-likelihood that the given input vector belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput, Double)
Computes the log-likelihoods that the given input vectors belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput, Int32)
Predicts a class label vector for each input vector, returning the log-likelihoods of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput, Boolean, Double)
Predicts a class label vector for the given input vector, returning the log-likelihoods of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodLogLikelihoods(TInput, Boolean, Double)
Predicts a class label vector for each input vector, returning the log-likelihoods of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProbabilities(TInput)
Computes the probabilities that the given input vector belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbabilities(TInput)
Computes the probabilities that the given input vectors belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbabilities(TInput, Boolean)
Predicts a class label vector for the given input vector, returning the probabilities of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbabilities(TInput, Double)
Computes the probabilities that the given input vector belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbabilities(TInput, Double)
Computes the probabilities that the given input vectors belongs to each of the possible classes.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbabilities(TInput, Int32)
Predicts a class label vector for each input vector, returning the probabilities of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbabilities(TInput, Boolean, Double)
Predicts a class label vector for the given input vector, returning the probabilities of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbabilities(TInput, Boolean, Double)
Predicts a class label vector for each input vector, returning the probabilities of the input vector belonging to each possible class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbability(TInput)
Predicts a class label for the given input vector, returning the probability that the input vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbability(TInput)
Predicts a class label for the given input vector, returning the probability that the input vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbability(TInput, Boolean)
Predicts a class label for the given input vector, returning the probability that the input vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbability(TInput, Int32)
Predicts a class label for each input vector, returning the probability that each vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodProbability(Double, Double)
Predicts a class label for the given input vector, returning the probability that the input vector belongs to its predicted class.
(Overrides BinaryLikelihoodClassifierBaseTInputProbability(TInput, Double).)
Public methodProbability(TInput, Boolean, Double)
Predicts a class label for each input vector, returning the probability that each vector belongs to its predicted class.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodScore(TInput)
Computes a numerical score measuring the association between the given input vector and its most strongly associated class (as predicted by the classifier).
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScore(TInput)
Computes a numerical score measuring the association between the given input vector and its most strongly associated class (as predicted by the classifier).
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScore(TInput, Boolean)
Predicts a class label for the input vector, returning a numerical score measuring the strength of association of the input vector to its most strongly related class.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScore(TInput, Boolean)
Predicts a class label for each input vector, returning a numerical score measuring the strength of association of the input vector to the most strongly related class.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScore(Double, Double)
Computes a numerical score measuring the association between the given input vector and each class.
(Overrides BinaryLikelihoodClassifierBaseTInputScore(TInput, Double).)
Public methodScore(TInput, Boolean, Double)
Predicts a class label for each input vector, returning a numerical score measuring the strength of association of the input vector to the most strongly related class.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput)
Computes a numerical score measuring the association between the given input vector and each class.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput)
Computes a numerical score measuring the association between the given input vector and each class.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput, Boolean)
Predicts a class label vector for the given input vector, returning a numerical score measuring the strength of association of the input vector to each of the possible classes.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput, Double)
Computes a numerical score measuring the association between the given input vector and each class.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput, Boolean)
Predicts a class label vector for each input vector, returning a numerical score measuring the strength of association of the input vector to each of the possible classes.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput, Double)
Computes a numerical score measuring the association between the given input vector and each class.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput, Boolean, Double)
Predicts a class label vector for the given input vector, returning a numerical score measuring the strength of association of the input vector to each of the possible classes.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodScores(TInput, Boolean, Double)
Predicts a class label vector for each input vector, returning a numerical score measuring the strength of association of the input vector to each of the possible classes.
(Inherited from BinaryScoreClassifierBaseTInput.)
Public methodSetCoefficient
Sets a coefficient value, where 0 is the intercept term and the other coefficients are indexed starting at 1.
Public methodToMulticlass
Views this instance as a multi-class generative classifier, giving access to more advanced methods, such as the prediction of integer labels.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodToMultilabel
Views this instance as a multi-label generative classifier, giving access to more advanced methods, such as the prediction of one-hot vectors.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTransform(TInput)
Applies the transformation to an input, producing an associated output.
(Inherited from ClassifierBaseTInput, TClasses.)
Public methodTransform(TInput)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from TransformBaseTInput, TOutput.)
Public methodTransform(TInput, Boolean)
Applies the transformation to an input, producing an associated output.
(Inherited from BinaryClassifierBaseTInput.)
Public methodTransform(TInput, Int32)
Applies the transformation to an input, producing an associated output.
(Inherited from BinaryClassifierBaseTInput.)
Public methodTransform(TInput, Boolean)
Applies the transformation to an input, producing an associated output.
(Inherited from BinaryClassifierBaseTInput.)
Public methodTransform(TInput, Int32)
Applies the transformation to an input, producing an associated output.
(Inherited from BinaryClassifierBaseTInput.)
Public methodTransform(TInput, Int32)
Applies the transformation to an input, producing an associated output.
(Inherited from BinaryClassifierBaseTInput.)
Public methodTransform(TInput, Double)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodTransform(TInput, Double)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodTransform(TInput, Double)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from BinaryLikelihoodClassifierBaseTInput.)
Public methodTransform(TInput, TClasses)
Applies the transformation to an input, producing an associated output.
(Inherited from ClassifierBaseTInput, TClasses.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

References:

  • Bishop, Christopher M.; Pattern Recognition and Machine Learning. Springer; 1st ed. 2006.
  • Amos Storkey. (2005). Learning from Data: Learning Logistic Regressors. School of Informatics. Available on: http://www.inf.ed.ac.uk/teaching/courses/lfd/lectures/logisticlearn-print.pdf
  • Cosma Shalizi. (2009). Logistic Regression and Newton's Method. Available on: http://www.stat.cmu.edu/~cshalizi/350/lectures/26/lecture-26.pdf
  • Edward F. Conor. Logistic Regression. Website. Available on: http://userwww.sfsu.edu/~efc/classes/biol710/logistic/logisticreg.htm

Examples
// Suppose we have the following data about some patients.
// The first variable is continuous and represent patient
// age. The second variable is dichotomic and give whether
// they smoke or not (This is completely fictional data).

// We also know if they have had lung cancer or not, and 
// we would like to know whether smoking has any connection
// with lung cancer (This is completely fictional data).

double[][] input =
{              // age, smokes?, had cancer?
    new double[] { 55,    0  }, // false - no cancer
    new double[] { 28,    0  }, // false
    new double[] { 65,    1  }, // false
    new double[] { 46,    0  }, // true  - had cancer
    new double[] { 86,    1  }, // true
    new double[] { 56,    1  }, // true
    new double[] { 85,    0  }, // false
    new double[] { 33,    0  }, // false
    new double[] { 21,    1  }, // false
    new double[] { 42,    1  }, // true
};

bool[] output = // Whether each patient had lung cancer or not
{
    false, false, false, true, true, true, false, false, false, true
};


// To verify this hypothesis, we are going to create a logistic
// regression model for those two inputs (age and smoking), learned
// using a method called "Iteratively Reweighted Least Squares":

var learner = new IterativeReweightedLeastSquares<LogisticRegression>()
{
    Tolerance = 1e-4,  // Let's set some convergence parameters
    Iterations = 100,  // maximum number of iterations to perform
    Regularization = 0
};

// Now, we can use the learner to finally estimate our model:
LogisticRegression regression = learner.Learn(input, output);

// At this point, we can compute the odds ratio of our variables.
// In the model, the variable at 0 is always the intercept term, 
// with the other following in the sequence. Index 1 is the age
// and index 2 is whether the patient smokes or not.

// For the age variable, we have that individuals with
//   higher age have 1.021 greater odds of getting lung
//   cancer controlling for cigarette smoking.
double ageOdds = regression.GetOddsRatio(1); // 1.0208597028836701

// For the smoking/non smoking category variable, however, we
//   have that individuals who smoke have 5.858 greater odds
//   of developing lung cancer compared to those who do not 
//   smoke, controlling for age (remember, this is completely
//   fictional and for demonstration purposes only).
double smokeOdds = regression.GetOddsRatio(2); // 5.8584748789881331

// If we would like to use the model to predict a probability for
// each patient regarding whether they are at risk of cancer or not,
// we can use the Probability function:

double[] scores = regression.Probability(input);

// Finally, if we would like to arrive at a conclusion regarding
// each patient, we can use the Decide method, which will transform
// the probabilities (from 0 to 1) into actual true/false values:

bool[] actual = regression.Decide(input);
See Also