Ask Your Question
1

How can I reduce vector dimension using PCA?

asked 2013-05-23 03:17:39 -0600

Nihad gravatar image

updated 2013-05-23 03:18:26 -0600

I am trying to reduced vector size usig PCA. I am dealing with 907 objects(row), and each object has 300 feature vector(col.). I want to reduce feature vector size 50% which means resultant feature vector would be 150(col.) I use following code segment, but it retains all col. How can I reduce using PCA? Thnx in advance.

code:

int main(..)
{
.......Read read_feature two dimensional array////////////////
number_of_lines=907;
feature_vector_size=300;
Mat input_feature_vector(number_of_lines,feature_vector_size,CV_32F);

    for(i=0;i<number_of_lines;i++)
    {
        for(j=0;j<feature_vector_size;j++)
        {
            input_feature_vector.at<float>(i,j)=read_feature[i][j];

        }

    }

    cout<<input_feature_vector<<endl;

    Mat projection_result;

    PCA pca(input_feature_vector,Mat(),CV_PCA_DATA_AS_ROW, 0); 

    /*cout<<"PCA Mean:"<<endl;
    cout<<pca.mean<<endl;*/

    pca.project(input_feature_vector,projection_result);

    cout<<"PCA Projection Result:"<<endl;
    cout<<projection_result<<endl;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-23 03:36:06 -0600

Guanta gravatar image

you need to specify the maxComponents that PCA should retain, i.e. change

PCA pca(input_feature_vector,Mat(),CV_PCA_DATA_AS_ROW, 0);

to

PCA pca(input_feature_vector,Mat(),CV_PCA_DATA_AS_ROW, 150);
edit flag offensive delete link more

Comments

thank you. it works fine.

Nihad gravatar imageNihad ( 2013-05-23 03:38:03 -0600 )edit

Question Tools

Stats

Asked: 2013-05-23 03:17:39 -0600

Seen: 2,971 times

Last updated: May 23 '13