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.