0

I am using C++ with OpenCV 3.0.

I have a training data matrix with features that I have extracted of some images (trainData). The size of this matrix is 2750x1104 because I have 2750 images (positive and negative) with 1104 features each. I have other matrix of 2750x1 with the labels (trainLabels).

  • trainData: 2750 images x 1104 features.
  • trainLabels: 2750 images x 1 label per column

With this information I want to train a SVM and I would like to evaluate the performance of using PCA (Principal Component Analysis), LDA (Linear Discriminative Analysis) and a combination of both. I have applied PCA without problems but when I use LDA I obtain a matrix of 2750x1 (projected) that the SVM cannot use as input.

I have used this link, but they do not employ SVM.

This is the code:

LDA lda(trainData, trainLabels, num_components);
Mat eigenvectors = lda.eigenvectors();
Mat projected = lda.project(trainData);

I have selected num_components as 1 because I have two classes (person & no person).

And these are my results:

  • eigenvectors: 1104 rows x 1 column
  • projected: 2750 rows x 1 column

As far I understand eigenvectors should be 1104x1104 and projected 2750x1104 so the SVM can be trained with the matrix projected.

I don't know if I am really wrong in the code, maybe I do not understand correctly how LDA works. If so, could you give me some tips? In fact, could I train a SVM with LDA?

Thanks in advance.

Jose L
  • 322
  • 3
  • 13
  • 1
    first of all PCA is not "Program Analysis Components" but "Principal Component Analysis". Second of all LDA (Linear Discriminant Analysis) is a classifier, not dimensionality reduction technique. LDA is "of the same level of abstraction" as SVM, not as PCA. – lejlot Jul 12 '16 at 19:03
  • You are right, thanks! I'm going to edit that. – Jose L Jul 13 '16 at 09:13
  • 1
    The second part of my comment is crucial. Lda is not preprocessing technique. There is no such thing as "use svm with lda". It is like asking "can i use svm with logistic regression" or even "can i use svm with svm". Unless you are thinking about Latent Dirichlet Allocation (also lda but completely different thing) – lejlot Jul 13 '16 at 10:17
  • Okey, thanks! Then I have three options: SVM, PCA+SVM and PCA+LDA, right? – Jose L Jul 13 '16 at 10:45
  • And plenty more, but yeah. These three are fine. For completeness add pure LDA as well – lejlot Jul 13 '16 at 12:11
  • Perfect, thank you very much! :) – Jose L Jul 14 '16 at 13:50
  • 1
    @lejlot LDA is a dimensional reduction technique and a classifier too. pls see this link bit.ly/2CsAJI1 – Amir Sep 01 '19 at 16:47

0 Answers0