Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How can I reduce vector dimension using PCA?

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); ///error msg

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

    pca.project(input_feature_vector,projection_result);

    cout<<"PCA Projection Result:"<<endl;
    cout<<projection_result<<endl;
}

How can I reduce vector dimension using PCA?

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); ///error msg
 
    /*cout<<"PCA Mean:"<<endl;
    cout<<pca.mean<<endl;*/

    pca.project(input_feature_vector,projection_result);

    cout<<"PCA Projection Result:"<<endl;
    cout<<projection_result<<endl;
}