Diagonal Linear Discriminant Analysis.
Example:
>>> from numpy import *
>>> from mlpy import *
>>> xtr = array([[1.1, 2.4, 3.1, 1.0], # first sample
... [1.2, 2.3, 3.0, 2.0], # second sample
... [1.3, 2.2, 3.5, 1.0], # third sample
... [1.4, 2.1, 3.2, 2.0]]) # fourth sample
>>> ytr = array([1, -1, 1, -1]) # classes
>>> mydlda = Dlda() # initialize dlda class
>>> xtr_std = data_standardize(xtr) # standardize the training dataset
>>> mydlda.compute(xtr_std, ytr) # compute dlda
1
>>> mydlda.predict(xtr_std) # predict dlda model on training data
array([ 1, -1, 1, -1])
>>> xts = array([4.0, 5.0, 6.0, 7.0]) # test point
>>> mydlda.predict(xts) # predict dlda model on test point
-1
>>> mydlda.realpred # real-valued prediction
-45.32292203746583
>>> mydlda.weights(xtr_std, ytr) # compute weights on training data
array([ 3.00000000e+00, 3.00000000e+00, 9.32587341e-15,
2.61756029e+00])
Initialize Dlda class.
Input:
- nf - [integer] the number of the best features that we want to use in the model (1 <= nf >= #features). If nf = 0 the system stops at a number of features corresponding to a peak of accuracy
- tol - [integer] in case of nf = 0 it’s the number of steps of classification to be calculated after the peak to avoid a local maximum
- overview - [bool] set True to print informations about the accuracy of the classifier at every step of the compute
- bal - [bool] set True if it’s reasonable to consider the unbalancement of the test set similar to the one of the training set
Compute Dlda model.
Initialize array of alphas a.
Input
- x - [2D numpy array float] (sample x feature) training data
- y - [1D numpy array integer] (two classes) classes
- mf - [integer] (More Features) number of classification steps to be calculated more on a model already computed
Predict Dlda model on test point(s).
Input
- p - [1D or 2D numpy array float] test point(s)
Output
- cl - [integer or 1D numpy array integer] class(es) predicted
- self.realpred - [1D numpy array float] real valued prediction
Return feature weights.
Input
- x - [2D numpy array float] (sample x feature) training data
- y - [1D numpy array integer] (two classes, 1 or -1) classes
Output
- fw - [1D numpy array float] feature weights (they are gonna be > 0 for the features chosen for the classification and = 0 for all the others)