Package smile.classification
Class QDA
java.lang.Object
smile.classification.AbstractClassifier<double[]>
smile.classification.QDA
- All Implemented Interfaces:
Serializable
,ToDoubleFunction<double[]>
,ToIntFunction<double[]>
,Classifier<double[]>
- Direct Known Subclasses:
RDA
Quadratic discriminant analysis. QDA is closely related to linear discriminant
analysis (LDA). Like LDA, QDA models the conditional probability density
functions as a Gaussian distribution, then uses the posterior distributions
to estimate the class for a given test data. Unlike LDA, however,
in QDA there is no assumption that the covariance of each of the classes
is identical. Therefore, the resulting separating surface between
the classes is quadratic.
The Gaussian parameters for each class can be estimated from training data
with maximum likelihood (ML) estimation. However, when the number of
training instances is small compared to the dimension of input space,
the ML covariance estimation can be ill-posed. One approach to resolve
the ill-posed estimation is to regularize the covariance estimation.
One of these regularization methods is regularized discriminant analysis
.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface smile.classification.Classifier
Classifier.Trainer<T,
M extends Classifier<T>> -
Field Summary
Fields inherited from class smile.classification.AbstractClassifier
classes
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic QDA
fit
(double[][] x, int[] y) Fits quadratic discriminant analysis.static QDA
fit
(double[][] x, int[] y, double[] priori, double tol) Fits quadratic discriminant analysis.static QDA
fit
(double[][] x, int[] y, Properties params) Fits quadratic discriminant analysis.int
predict
(double[] x) Predicts the class label of an instance.int
predict
(double[] x, double[] posteriori) Predicts the class label of an instance and also calculate a posteriori probabilities.double[]
priori()
Returns a priori probabilities.boolean
soft()
Returns true if this is a soft classifier that can estimate the posteriori probabilities of classification.Methods inherited from class smile.classification.AbstractClassifier
classes, numClasses
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface smile.classification.Classifier
applyAsDouble, applyAsInt, online, predict, predict, predict, predict, predict, predict, score, update, update, update
-
Constructor Details
-
QDA
Constructor.- Parameters:
priori
- a priori probabilities of each class.mu
- the mean vectors of each class.eigen
- the eigen values of each variance matrix.scaling
- the eigen vectors of each covariance matrix.
-
QDA
Constructor.- Parameters:
priori
- a priori probabilities of each class.mu
- the mean vectors of each class.eigen
- the eigen values of each variance matrix.scaling
- the eigen vectors of each covariance matrix.labels
- the class label encoder.
-
-
Method Details
-
fit
Fits quadratic discriminant analysis.- Parameters:
x
- training samples.y
- training labels in [0, k), where k is the number of classes.- Returns:
- the model.
-
fit
Fits quadratic discriminant analysis.- Parameters:
x
- training samples.y
- training labels.params
- the hyper-parameters.- Returns:
- the model.
-
fit
Fits quadratic discriminant analysis.- Parameters:
x
- training samples.y
- training labels in [0, k), where k is the number of classes.priori
- the priori probability of each class. If null, it will be estimated from the training data.tol
- a tolerance to decide if a covariance matrix is singular; it will reject variables whose variance is less than tol2.- Returns:
- the model.
-
priori
public double[] priori()Returns a priori probabilities.- Returns:
- a priori probabilities.
-
predict
public int predict(double[] x) Description copied from interface:Classifier
Predicts the class label of an instance.- Parameters:
x
- the instance to be classified.- Returns:
- the predicted class label.
-
soft
public boolean soft()Description copied from interface:Classifier
Returns true if this is a soft classifier that can estimate the posteriori probabilities of classification.- Returns:
- true if soft classifier.
-
predict
public int predict(double[] x, double[] posteriori) Description copied from interface:Classifier
Predicts the class label of an instance and also calculate a posteriori probabilities. Classifiers may NOT support this method since not all classification algorithms are able to calculate such a posteriori probabilities.- Parameters:
x
- an instance to be classified.posteriori
- a posteriori probabilities on output.- Returns:
- the predicted class label
-