Logistic Regression Analysis.
Inheritance Hierarchy Namespace: Accord.Statistics.AnalysisAccord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax[SerializableAttribute] public class LogisticRegressionAnalysis : TransformBase<double[], double>, IRegressionAnalysis, IMultivariateAnalysis, IAnalysis, ISupervisedLearning<LogisticRegression, double[], int>, ISupervisedLearning<LogisticRegression, double[], double>
<SerializableAttribute> Public Class LogisticRegressionAnalysis Inherits TransformBase(Of Double(), Double) Implements IRegressionAnalysis, IMultivariateAnalysis, IAnalysis, ISupervisedLearning(Of LogisticRegression, Double(), Integer), ISupervisedLearning(Of LogisticRegression, Double(), Double)Request Example View Source
The LogisticRegressionAnalysis type exposes the following members.
Constructors Name Description LogisticRegressionAnalysisConstructs a Logistic Regression Analysis.
LogisticRegressionAnalysis(Double, Double) Obsolete.Constructs a Logistic Regression Analysis.
LogisticRegressionAnalysis(Double, Double, Double) Obsolete.Constructs a Logistic Regression Analysis.
LogisticRegressionAnalysis(Double, Double, String, String) Obsolete.Constructs a Logistic Regression Analysis.
LogisticRegressionAnalysis(Double, Double, Double, String, String) Obsolete.Constructs a Logistic Regression Analysis.
Top Properties Name Description Array Obsolete.Gets the source matrix from which the analysis was run.
ChiSquareGets the Chi-Square (Likelihood Ratio) Test for the model.
CoefficientsGets the collection of coefficients of the model.
CoefficientValuesGets the value of each coefficient.
ComputeInnerModelsGets or sets whether nested models should be computed in order to calculate the likelihood-ratio test of each of the coefficients. Default is false.
ConfidencesGets the 95% Confidence Intervals (C.I.) for each coefficient found in the regression.
DevianceGets the Deviance of the model.
InformationMatrixGets the information matrix obtained during learning.
InputsGets or sets the name of the input variables for the model.
IterationsGets or sets the maximum number of iterations to be performed by the regression algorithm. Default is 50.
LikelihoodRatioTestsGets the Likelihood-Ratio Tests for each coefficient.
LogLikelihoodGets the Log-Likelihood for the model.
NumberOfInputsGets the number of inputs accepted by the model.
(Inherited from TransformBaseTInput, TOutput.) NumberOfOutputsGets the number of outputs generated by the model.
(Inherited from TransformBaseTInput, TOutput.) NumberOfSamplesGets the number of samples used to compute the analysis.
OddsRatiosGets the Odds Ratio for each coefficient found during the logistic regression.
OutputGets or sets the name of the output variable for the model.
Outputs Obsolete.Gets the dependent variable value for each of the source input points.
RegressionGets the Logistic Regression model created and evaluated by this analysis.
RegularizationGets or sets the regularization value to be added in the objective function. Default is 1e-10.
Result Obsolete.Gets the resulting probabilities obtained by the logistic regression model.
Source Obsolete.Gets the source matrix from which the analysis was run.
StandardErrorsGets the Standard Error for each coefficient found during the logistic regression.
TokenGets or sets a cancellation token that can be used to stop the learning algorithm while it is running.
ToleranceGets or sets the difference between two iterations of the regression algorithm when the algorithm should stop. The difference is calculated based on the largest absolute parameter change of the regression. Default is 1e-5.
WaldTestsGets the Wald Tests for each coefficient.
Weights Obsolete.Gets the sample weight associated with each input vector.
Top Methods Name Description Compute Obsolete.Computes the Logistic Regression Analysis.
Compute(LogisticRegression) Obsolete.Computes the Logistic Regression Analysis for an already computed regression.
Compute(Double, Int32) Obsolete.Computes the Logistic Regression Analysis.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object.) FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.) FromSummary Obsolete.Creates a new LogisticRegressionAnalysis from summarized data. In summary data, instead of having a set of inputs and their associated outputs, we have the number of times an input vector had a positive label in the data set and how many times it had a negative label.
GetConfidenceIntervalGets the confidence interval for a given input.
GetHashCodeServes as the default hash function.
(Inherited from Object.) GetLikelihoodRatio Obsolete.Gets the Log-Likelihood Ratio between this model and another model.
GetPredictionIntervalGets the prediction interval for a given input.
GetTypeGets the Type of the current instance.
(Inherited from Object.) Learn(Double, Double, Double)Learns a model that can map the given inputs to the given outputs.
Learn(Double, Int32, Double)Learns a model that can map the given inputs to the given outputs.
Learn(Double, Int32, Int32)Learns a model that can map the given inputs to the given outputs.
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object.) ToStringReturns a string that represents the current object.
(Inherited from Object.) Transform(TInput)Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from TransformBaseTInput, TOutput.) Transform(Double)Applies the transformation to an input, producing an associated output.
(Overrides TransformBaseTInput, TOutputTransform(TInput).) Transform(TInput, TOutput)Applies the transformation to an input, producing an associated output.
(Inherited from TransformBaseTInput, TOutput.) Top Extension Methods Name Description HasMethodChecks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) IsEqualCompares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.) To(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.) ToT 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.) Top RemarksThe Logistic Regression Analysis tries to extract useful information about a logistic regression model.
This class can also be bound to standard controls such as the DataGridView by setting their DataSource property to the analysis' Coefficients property.
References:
The following example shows to create a Logistic regresion analysis using a full dataset composed of input vectors and a binary output vector. Each input vector has an associated label (1 or 0) in the output vector, where 1 represents a positive label (yes, or true) and 0 represents a negative label (no, or false).
double[] coef = lra.CoefficientValues; double[] odds = lra.OddsRatios; double[] stde = lra.StandardErrors; double y = lra.Regression.Probability(new double[] { 87, 1 }); DoubleRange ci = lra.GetConfidenceInterval(new double[] { 87, 1 });
The resulting table is shown below.
double[][] inputs = { new double[] { 55, 0 }, new double[] { 28, 0 }, new double[] { 65, 1 }, new double[] { 46, 0 }, new double[] { 86, 1 }, new double[] { 56, 1 }, new double[] { 85, 0 }, new double[] { 33, 0 }, new double[] { 21, 1 }, new double[] { 42, 1 }, }; double[] output = { 0, 0, 0, 1, 1, 1, 0, 0, 0, 1 }; var lra = new LogisticRegressionAnalysis() { Regularization = 0 }; LogisticRegression regression = lra.Learn(inputs, output);
The analysis can also be created from data given in a summary form. Instead of having one input vector associated with one positive or negative label, each input vector is associated with the proportion of positive to negative labels in the original dataset.
int[,] data = { { 1, 140, 45 }, { 2, 130, 60 }, { 3, 150, 31 }, { 4, 96, 65 } }; double[][] inputs = data.GetColumn(0).ToDouble().ToJagged(); int[] positive = data.GetColumn(1); int[] negative = data.GetColumn(2); var lra = new LogisticRegressionAnalysis(); LogisticRegression regression = lra.Learn(inputs, positive, negative); double[] coef = lra.CoefficientValues; double[] odds = lra.OddsRatios; double[] stde = lra.StandardErrors; double y = lra.Regression.Probability(new double[] { 4 });
The last example shows how to learn a logistic regression analysis using data given in the form of a System.Data.DataTable. This data is also heterogeneous, mixing both discrete (symbol) variables and continuous variables. This example is also available for MultipleLinearRegressionAnalysis.
var data = new DataTable("Customer Revenue Example"); data.Columns.Add("Day", "CustomerId", "Time (hour)", "Weather", "Buy"); data.Rows.Add("D1", 0, 8, "Sunny", true); data.Rows.Add("D2", 1, 10, "Sunny", true); data.Rows.Add("D3", 2, 10, "Rain", false); data.Rows.Add("D4", 3, 16, "Rain", true); data.Rows.Add("D5", 4, 15, "Rain", true); data.Rows.Add("D6", 5, 20, "Rain", false); data.Rows.Add("D7", 6, 12, "Cloudy", true); data.Rows.Add("D8", 7, 12, "Sunny", false); var codebook = new Codification() { { "Weather", CodificationVariable.Categorical }, { "Time (hour)", CodificationVariable.Continuous }, { "Revenue", CodificationVariable.Continuous }, }; codebook.Learn(data); string[] inputNames; string outputName; double[][] inputs = codebook.Apply(data, "Weather", "Time (hour)").ToJagged(out inputNames); double[] outputs = codebook.Apply(data, "Buy").ToVector(out outputName); var lra = new LogisticRegressionAnalysis() { Inputs = inputNames, Output = outputName }; LogisticRegression regression = lra.Learn(inputs, outputs); double predicted = lra.Transform(inputs[0]); int inputCount = lra.NumberOfInputs; int outputCount = lra.NumberOfOutputs; double logl = lra.LogLikelihood; ChiSquareTest x2 = lra.ChiSquare; double[] stdErr = lra.StandardErrors; double[] or = lra.OddsRatios; LogisticCoefficientCollection c = lra.Coefficients; double[][] h = lra.InformationMatrix;See Also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4