# PCA + SVM ?

Hi, I am trying to reduce the dimensionality of my feature set using PCA and then classification using SVM.

I have created and populated my feature matrix and label matrix :

```
Mat labels(875, 1, CV_32F);
Mat trainingData(875, 23040, CV_32F);
```

Where each row corresponds to an image and each column is a feature. The features are histogram bins (256) from multiple regions in the image (90 regions). 90x256 = 23040.

I now want to reduce the 23040 features to something less before training, say 512 features. I have this:

```
/*Reduce dimensionality using PCA*/
Mat projection_result;
PCA pca(trainingData, Mat(), CV_PCA_DATA_AS_ROW,512);
pca.project(trainingData, projection_result);
/*Classification*/
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::RBF;
CvSVM SVM;
SVM.train_auto(projection_result, labels, Mat(), Mat(), params);
SVM.save("trainedData_test.xml");
```

My question is, is this correct ? And how would I now use prediction with PCA ?

```
/*Load SVM*/
CvSVM SVM;
SVM.load("trainedData_test.xml");
/*Populate test matrix*/
Mat testData(1, 23040, CV_32F);
/*PCA ???*/
/*Classify*/
int label = SVM.predict(projection_result ???);
```

Thanks !