Porting SVM to the C ++ Project

Source: Internet
Author: User
Tags svm

Recently, I have implemented SVM for a while and want to use it for classification. My advanced feature is the hog feature of the image, and the sample data is a 2340-dimensional vector. Description of libsvm on the InternetArticleAlmost all of them are the same. The most disgusting thing is that the general process is said, and few people talk about the specific steps. Even if SVM-train, SVM-scale, SVM-predict, and other executable files are used.

After some exploration, I finally successfully transplanted it to my ownProgram. There are several details:

1. Data Scale Processing

Previously, neither libsvm nor cvsvm in opencv could obtain the desired results. If it is replaced with simple sample data, it can be well classified, but after it is replaced with my 2340-dimensional data, the result is incorrect. All categories are-1 and sometimes all are 1. The cause of the problem is that the feature data is not normalized, which will make the big feature eat small features, and there are similar problems in the back-propagation neural network. In many articles, scale helps to select parameters and solve the SVM speed. In fact, it is quite important to say that scale processing is not performed when the data difference is large, the correct classification results will not be obtained.

Libsvm source code contains this partSource codeBut it's too long. The parameters he needs to pass are also difficult to understand. In fact, it doesn't have to be so troublesome. This part is just a scaling process, and a small function can be done.

2. classification or Prediction

Libsvm source code contains this part of the file svm-predict.c, the program implementation is a bit complex, in fact, can be simplified into a lineCode. The svm_predict function is used to input two parameters: the loaded model file and the normalized feature data file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.