Libsvm is an open source toolkit for implementing SVM algorithm (http://www.csie.ntu.edu.tw /~ Cjlin/libsvm/), I have recently used Libsvm for a custom kernel function. Many matlab versions on the Internet use the custom Kernel Function Matrix, for example: http://www.shamoxia.com/html/y2011/3003.html. However, Java and C ++ Versions differ from matlab versions. In addition, the latest version of Libsvm is added with a multi-classification solution. Therefore, I used the Java-version custom kernel function method.
For a custom kernel function, libsvm is called Precomputed Kernels. The example is as follows:
Assume the original training data has three four-feature instances and testing data has one instance:
15
25 3:1
15
If the linear kernel is used, we have the following new training/testing sets:
45
25
15 0 :?
? Can be any value.
Among them, 15, 45 and so on are categories, while the second is the matrix of the User-Defined Function. The calculated value is shown in the second matrix when the linear kernel is used. The details are as follows:
Category 0: Index (the number of the data records) 1: core function value 2 of the first data record, core function value of the second data record ...... N: the value of the nth data.
After the custom kernel function constructs the matrix, the call method is svm_train-t 4 [other optional parameters] kernel_file (Kernel Function Matrix file) Model_file (model file ). In this way, we can easily apply the kernel function matrix of Java and C ++ versions.