In the past few days, we have used some tools in libsvm (2.8.6) To summarize them.
Some libsvm tools are still very useful. you can call subset. PY sample your sample set according to the proportion you want to sample two subsample sets. 2. you can also call grid. PY performs cross-validation Parameter Selection on (C, gamma) to easily find the best parameter pair (C, gamma ). 3. you can also call easy. pH completes the whole SVM Mining Process in one step, and finally obtains the cross-validation accuracy, which includes the test accuracy of parameter pairs and test sets. 4. you can also call checkdata to check whether your data format is incorrect. these operations can save everyone a lot of trouble.
Libsvm (2.8.6) mainly has four tools: Easy. py, subset. py, grid. py, checkdata. py.
Running environment requirements and settings:
Two tools are required.
One tool is: ipv2.5.1; another tool is running gnuplot.exe, to the next network, I use, download gnuplot.exe to install the above software can not run, but also modify the settings of easy. py, grid. py.Code"Gnuplot_exe = r" C: \ TMP \ gnuplot \ bin \ pgnuplot.exe "" change the path of the specified pgnuplot.exe,
For example, if my file is in the upper-level directory of the current directory, that is, the same level directory as the Tools Folder, then my settings should be "gnuplot_exe = r ".. \ gnuplot \ bin \ pgnuplot.exe "".
This completes the settings. We only need to go to the console to run the fourProgramYou can.
Note: In the following Python command, all the sample datasets to be processed are stored in the tools directory by default, if the data file is not in the tools directory, we need to use the absolute path to specify the data location.
The following describes the call format:
From its documents, we can find that its functions are as follows:
(1) Easy. py: All the SVM mining steps can be completed with simple input, namely:
1. Conducting simple scaling on the data
2. Consider the RBF kernel K (X; y)
3. Use cross-validation to nd the best parameter C and
4. Use the best parameter C and to train the whole training set
5. Test
For beginners, this file is nothing more than a life-saving tool. You can simply look at its syntax:
Go to the directory where easy. py is located in the console:
$ Python easy. py train.3 test.3
Scaling training data... normalization data
Cross validation... cross validation on the training set
Best c = 128.0, G = 0.125 CV rate = 88.9186 (use the grid search method to perform cross verification on each parameter pair, and select the parameter with the highest cross verification accuracy .)
Training... (train the above parameters on the training set)
Output Model: crttrain. Model (Save the model to a file)
Scaling testing data... (normalized data)
Testing... (test the test set using the trained Model)
Accuracy = 87.8049% (36/41) (Classification) (test accuracy)
Output prediction: crttest. predict (output prediction result)
(In the cross-validation process, there will be a graphic interface showing the role of gnuplot.exe)
(2). Grid. py: used for cross-validation. Select the best parameter pair.
Usage:
Go to the directory where grid. py is located in the console:
$ Python grid. py crttrain
[Local] 5-7 86.9186 (best C = 32.0, G = 0.0078125, rate = 86.9186)
[Local]-1-7 85.1744 (best C = 32.0, G = 0.0078125, rate = 86.9186)
[Local] 5-1 77.0349 (best C = 32.0, G = 0.0078125, rate = 86.9186)
.......
[Local] 13-15 85.1744 (best C = 32.0, G = 0.0078125, rate = 86.9186)
[Local] 13 3 55.5233 (best C = 32.0, G = 0.0078125, rate = 86.9186)
[Local] 13-9 83.1395 (best C = 32.0, G = 0.0078125, rate = 86.9186)
[Local] 13-3 79.6512 (best C = 32.0, G = 0.0078125, rate = 86.9186)
32.0 0.0078125 86.9186 (C = 32, Gamma = 0.0078125 cross verification accuracy)
(3) subset. py is used to split the sample integration training set and test set by number.
Usage:
Go to the subset. py directory in the console:
$ Python subset. py CRT 100 crttrain crttest
Parameter description:
CRT: Sample Set;
100: number of training set samples;
Crttrain: stores 100 training samples;
Crttest: stores the remaining sample set as the test set;
If the operation is successful, no output information is displayed. Otherwise, an error message is displayed.
(4) checkdata. py is used to check whether the storage format of the sample set is correct.
Go to the subset. py directory in the console:
$ Python checkdata. py CRT
No error. (indicating no error)