Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I used the opencv CVSVM with bag of visual words to classify objects ,once i finish training i test the classifier on the same training set as this supposed give me 100% accuracy isn't it ? but that not the situation can someone explain why ?
 //load some class_1 samples into matrix
//load the associated SVM parameter file into SVM
//test (predict)
Mat test_samples;
CvSVM classifier;


FileStorage fs ("train_sample/training_samples-1000.yaml.gz" , FileStorage::READ) ;
if ( !fs.isOpened() ){
    cerr << "Cannot open file " << endl ;
    return ;
}

classifier.load("SVM_parameter_files/svm_1000_auto/SVM_classifier_class_1.yaml") ;
string class_= "class_";
for ( size_t i = 1 ; i <= 24; i++ ){
    stringstream ss ;
    ss << class_ <<i ;
    fs[ss.str()] >>test_samples;
    size_t positive  =  0 ;
    size_t negative = 0 ; 
    //test svm classifier that classify class_1 as positive and others as negative
    for ( int i = 0 ; i < test_samples.rows ; i++ ){
        float res = classifier.predict(test_samples.row(i),false  ) ;
       ( (res == 1) ? (positive++):(negative++) );

    }

    cout << ss.str() << " positive examples  = " <<positive <<" , negative examples =" << negative  << endl ;

}
fs.release();

output:
Output
Posted
Updated 16-Apr-15 0:50am
v3

1 solution

Some of your training sets might be seen as outliers by the SVM best splitting hyperplane. As the learning algorithm tries to find the best splitting hyperplane, it might not find one that is 100% accurate but one with the lowest misclassification error. Since the hyperplanes are smooth, they can't just have any shape, you can try out different kernels for your SVM to change the possible shapes of the splitting hyperplanes and pick the one that gives the lowest misclassification error.

If you use complex kernels, you might get a 100% accuracy on your training set, but then, you will have a problem of overfitting, thus you must trade carefully. Usually you need a separate validation set that's different from your training set.

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900