Click or drag to resize
Accord.NET (logo) LinearDiscriminantAnalysis Class
Linear Discriminant Analysis (LDA).
Inheritance Hierarchy
SystemObject
  Accord.MachineLearningTransformBaseDouble, Double
    Accord.Statistics.AnalysisBaseDiscriminantAnalysis
      Accord.Statistics.AnalysisLinearDiscriminantAnalysis

Namespace:  Accord.Statistics.Analysis
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.4.0
Syntax
[SerializableAttribute]
public class LinearDiscriminantAnalysis : BaseDiscriminantAnalysis, 
	IDiscriminantAnalysis, IMultivariateAnalysis, IAnalysis, IProjectionAnalysis, ISupervisedLearning<LinearDiscriminantAnalysisPipeline, double[], int>
Request Example View Source

The LinearDiscriminantAnalysis type exposes the following members.

Constructors
Properties
  NameDescription
Protected propertyClassCount
Gets the observation count for each class.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyClasses
Gets information about the distinct classes in the analyzed data.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyClassifications Obsolete.
Gets the original classifications (labels) of the source data given on the moment of creation of this analysis object.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyClassifier
Protected propertyClassMeans
Gets the Mean vector for each class.
(Inherited from BaseDiscriminantAnalysis.)
Protected propertyClassScatter
Gets the Scatter matrix for each class.
(Inherited from BaseDiscriminantAnalysis.)
Protected propertyClassStandardDeviations
Gets the Standard Deviation vector for each class.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyCumulativeProportions
The cumulative distribution of the discriminants factors proportions. Also known as the cumulative energy of the first dimensions of the discriminant space or as the amount of variance explained by those dimensions.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyDiscriminantMatrix Obsolete.
Gets the Eigenvectors obtained during the analysis, composing a basis for the discriminant factor space.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyDiscriminantProportions
Gets the level of importance each discriminant factor has in discriminant space. Also known as amount of variance explained.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyDiscriminants
Gets the discriminant factors in a object-oriented fashion.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyDiscriminantVectors
Gets the Eigenvectors obtained during the analysis, composing a basis for the discriminant factor space.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyEigenvalues
Gets the Eigenvalues found by the analysis associated with each vector of the ComponentMatrix matrix.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyMeans
Gets the mean of the original data given at method construction.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyNumberOfClasses
Gets the number of classes in the analysis.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyNumberOfInputs
Gets the number of inputs accepted by the model.
(Inherited from TransformBaseTInput, TOutput.)
Public propertyNumberOfOutputs
Gets the number of outputs generated by the model.
(Inherited from TransformBaseTInput, TOutput.)
Public propertyNumberOfSamples
Gets the number of samples used to create the analysis.
(Inherited from BaseDiscriminantAnalysis.)
Protected propertyProjectionMeans
Gets the feature space mean of the projected data.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyResult Obsolete.
Gets the resulting projection of the source data given on the creation of the analysis into discriminant space.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyScatterBetweenClass
Gets the Between-Class Scatter Matrix for the data.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyScatterMatrix
Gets the Total Scatter Matrix for the data.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyScatterWithinClass
Gets the Within-Class Scatter Matrix for the data.
(Inherited from BaseDiscriminantAnalysis.)
Public propertySource Obsolete.
Returns the original supplied data to be analyzed.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyStandardDeviations
Gets the standard mean of the original data given at method construction.
(Inherited from BaseDiscriminantAnalysis.)
Public propertyThreshold
Gets or sets the minimum variance proportion needed to keep a discriminant component. If set to zero, all components will be kept. Default is 0.001 (all components which contribute less than 0.001 to the variance in the data will be discarded).
(Inherited from BaseDiscriminantAnalysis.)
Public propertyToken
Gets or sets a cancellation token that can be used to stop the learning algorithm while it is running.
(Inherited from BaseDiscriminantAnalysis.)
Top
Methods
  NameDescription
Public methodClassify(Double) Obsolete.
Transform Classifies a new instance into one of the available classes.
(Overrides BaseDiscriminantAnalysisClassify(Double).)
Public methodClassify(Double) Obsolete.
Classifies new instances into one of the available classes.
(Overrides BaseDiscriminantAnalysisClassify(Double).)
Public methodClassify(Double, Double) Obsolete.
Classifies a new instance into one of the available classes.
(Overrides BaseDiscriminantAnalysisClassify(Double, Double).)
Public methodCompute Obsolete.
Computes the Multi-Class Linear Discriminant Analysis algorithm.
Protected methodCreateDiscriminants
Creates additional information about principal components.
(Inherited from BaseDiscriminantAnalysis.)
Public methodDiscriminantFunction
Gets the output of the discriminant function for a given class.
(Overrides BaseDiscriminantAnalysisDiscriminantFunction(Double, Int32).)
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 methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetNumberOfDimensions
Returns the minimum number of discriminant space dimensions (discriminant factors) required to represent a given percentile of the data.
(Inherited from BaseDiscriminantAnalysis.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodinit Obsolete.
Obsolete.
(Inherited from BaseDiscriminantAnalysis.)
Protected methodInit
Initializes common properties.
(Inherited from BaseDiscriminantAnalysis.)
Public methodLearn
Learns a model that can map the given inputs to the given outputs.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTransform(Double) Obsolete.
Obsolete.
(Inherited from BaseDiscriminantAnalysis.)
Public methodTransform(Double)
Applies the transformation to an input, producing an associated output.
(Inherited from BaseDiscriminantAnalysis.)
Public methodTransform(Double)
Applies the transformation to an input, producing an associated output.
(Inherited from BaseDiscriminantAnalysis.)
Public methodTransform(Double, Int32) Obsolete.
Obsolete.
(Inherited from BaseDiscriminantAnalysis.)
Public methodTransform(Double, Int32) Obsolete.
Obsolete.
(Inherited from BaseDiscriminantAnalysis.)
Public methodTransform(Double, Int32) Obsolete.
Obsolete.
(Inherited from BaseDiscriminantAnalysis.)
Public methodTransform(Double, Double)
Applies the transformation to an input, producing an associated output.
(Overrides TransformBaseTInput, TOutputTransform(TInput, TOutput).)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(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.)
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 Matrix.)
Top
Remarks

Linear Discriminant Analysis (LDA) is a method of finding such a linear combination of variables which best separates two or more classes.

In itself LDA is not a classification algorithm, although it makes use of class labels. However, the LDA result is mostly used as part of a linear classifier. The other alternative use is making a dimension reduction before using nonlinear classification algorithms.

It should be noted that several similar techniques (differing in requirements to the sample) go together under the general name of Linear Discriminant Analysis. Described below is one of these techniques with only two requirements:

  1. The sample size shall exceed the number of variables, and
  2. Classes may overlap, but their centers shall be distant from each other.

Moreover, LDA requires the following assumptions to be true:

  • Independent subjects.
  • Normality: the variance-covariance matrix of the predictors is the same in all groups.

If the latter assumption is violated, it is common to use quadratic discriminant analysis in the same manner as linear discriminant analysis instead.

This class can also be bound to standard controls such as the DataGridView by setting their DataSource property to the analysis' Discriminants property.

References:

  • R. Gutierrez-Osuna, Linear Discriminant Analysis. Available on: http://research.cs.tamu.edu/prism/lectures/pr/pr_l10.pdf

Examples
// Create some sample input data instances. This is the same
// data used in the Gutierrez-Osuna's example available on:
// http://research.cs.tamu.edu/prism/lectures/pr/pr_l10.pdf

double[][] inputs = 
{
    // Class 0
    new double[] {  4,  1 }, 
    new double[] {  2,  4 },
    new double[] {  2,  3 },
    new double[] {  3,  6 },
    new double[] {  4,  4 },

    // Class 1
    new double[] {  9, 10 },
    new double[] {  6,  8 },
    new double[] {  9,  5 },
    new double[] {  8,  7 },
    new double[] { 10,  8 }
};

int[] output = 
{
    0, 0, 0, 0, 0, // The first five are from class 0
    1, 1, 1, 1, 1  // The last five are from class 1
};

// We will create a LDA object for the data
var lda = new LinearDiscriminantAnalysis();

// Compute the analysis and create a classifier
var classifier = lda.Learn(inputs, output);

// Now we can project the data into LDA space:
double[][] projection = lda.Transform(inputs);

// Or perform classification using:
int[] results = classifier.Decide(inputs);
See Also