Sometimes we need to use the SVR (support vector regression) method, and Matlab's own SVM toolbox can not do regression analysis, so there is the intention to install the LIBSVM package.
There are some difficulties in the middle, such as unable to find the compiler and so on, after an afternoon and a night of effort, in MATLAB can use LIBSVM.
1. Download Good LIBSVM Package
Download libsvm-3.21 to a random place, such as to the MATLAB installation path under the Toolbox under--d:\matlab\r2014a\toolbox\, and unzip.
Open matlab and add Libsvm-3.21\matlab to the path, such as adding: \matlab\r2014a\toolbox\libsvm-3.21\matlab to the path.
Setup is trying for the first time
If the prompt does not have a C + + compiler, then download Winsdk_web.exe according to the prompt URL, and then double-click Run Winsdk_web.exe, install to the end if the prompt fails, go to uninstall your own Visual Studio and. NETFramework 4, and then run Winsdk_web.exe, the hint is missing. NETFramework 4, download the installation yourself and run the Winsdk_web.exe repeatedly.
Until you run Winsdk_web.exe, as shown, it's a step closer to success,
2. Setup
Open matlab, enter the LIBSVM root directory of the MATLAB directory (such as D:\MATLAB\R2014A\toolbox\libsvm-3.21), in the command window input mex-setup output is:
>>Mex–setupmex configured to use'Microsoft Windows SDK 7.1 (C)'For C language compilation. warning:the matlab C and Fortran API have changed to support MATLAB variables with more than2^ +-1elements. in the that near future you'll be required to update your code to utilize theNewApi. You can find more information about Thisat:http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.to select a different language, select a command from the following options: Mex-setup C + +Mex-setup FORTRAN
Go on:
>> mex-setup C+ +'Microsoft Windows SDK 7.1 (c + +)' for C + + language compilation. warning:the matlab C and Fortran API have changed to support MATLAB 2^1 element S. In the-future you'll be required to update your code to utilize thenew this At : http://www.mathworks.com/help/matlab/matlab_external/ upgrading-mex-files-to-use-64-bit-api.html.
3. Compiling
Execute make and the output is as follows:
>>Make uses'Microsoft Windows SDK 7.1 (C)'compile. The MEX has been successfully completed. Use'Microsoft Windows SDK 7.1 (C)'compile. The MEX has been successfully completed. Use'Microsoft Windows SDK 7.1 (c + +)'compile. I can't find the D:\MATLAB\R2014A\TOOLBOX\LIBSVM .-3.21\matlab\svmtrain.exp can't find D:\MATLAB\R2014A\TOOLBOX\LIBSVM .-3.21The \matlab\svmtrain.expmex has been successfully completed. Use'Microsoft Windows SDK 7.1 (c + +)'compile. I can't find the D:\MATLAB\R2014A\TOOLBOX\LIBSVM .-3.21\matlab\svmpredict.exp can't find D:\MATLAB\R2014A\TOOLBOX\LIBSVM .-3.21The \matlab\svmpredict.expmex has been successfully completed. >>
4. renaming
Ignore the error (Cannot find ...) ), continue, after compilation, the current directory (under Libsvm-3.21/matlab) will appear svmtrain.mexw64, svmpredict.mexw64, or Svmtrain.mexw32, Svmpredict.mexw32, Change the file name Svmtrain and svmpredict accordingly to Libsvmtrain and libsvmpredict.
This is because MATLAB in the Toolbox with SVM, its function name is Svmtrain and Svmpredict, and LIBSVM the default name.
5
. Test whether the installation was successful LIBSVM
The LIBSVM software package comes with test data, the heart_scale file under the package root directory.
To run the code in MATLAB, the output is as follows:
>> [Heart_scale_label, Heart_scale_inst] = Libsvmread ('Heart_scale');>> model = Libsvmtrain (Heart_scale_label, Heart_scale_inst,'- c 1-g 0.07');*optimization finished, #iter=134Nu=0.433785obj= -101.855060, Rho =0.426412NSV= the, NBSV =107Total NSV= the>> [Predict_label, accuracy, dec_values] =libsvmpredict (Heart_scale_label, heart_scale_inst, model); Accuracy=86.6667% (234/ the) (classification)
How to install LIBSVM package in MATLAB