Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Record the problems encountered in integrating LibSVM in MATLAB during the learning of ML

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

A few days ago, I wrote about my understanding of the key distance issues in SVM, and then I will continue to record my understanding of other problems in the model. Today, I would like to try the effect of SVM on the "Alpha 3.0" dataset in Watermelon Book. So we found an open source package LibSVM written by "Bay" professor Mr. Lin Zhiren, Daniel, etc., and the library is compatible with many platforms and has many language versions supporting java, C++, C, MATLAB and so on. We can download it from Professor Lin's home page. LibSVM address: http://www.csie.ntu.edu.tw/~cjlin/libsvm/ Magi Windows platform downloads Zip compressed file, under Linux is tar.gz, the new version of the package is 3.x. The version number of my MATLAB development platform is R2016a under Windows, so I record the process of integrating the open source package with R2016a.

First of all, I found a faruto boss post on matlabsky about this issue, so I followed the description of the post for related operations, but stepped on several holes, because this post is a long time ago, the version is relatively front, so there will be some details different, but generally can be referenced. And there is also a video explanation for reference.

Original address: http://www.matlabsky.com/thread-11925-1-1.html

Youku video: http://v.youku.com/v_showMini/id_XMjc2NTY3MzYw_ft_131.html

Step1: add the search directory (path) of LibSVM

Click the "set path" button under the home tab-> Click "add and include subfolders"-> Click the "libsvm-3.22" folder, select the directory you are in-> Save & close.

Step2: install the C++ compiler

In the post, I first run mex-setup and follow the prompts to choose, but before and after I install VC6.0, I will run the command with an error: "No compiler or SDK", that is, I can't find it with VC installed. I guess VC is too old. So instead of GCC, because the development package is developed by C++, it needs to be compiled by the relevant compiler before MATLAB can be called. As the new version of MATLAB supports the MinGW (GCC) compiler and is relatively small, I chose to install the compiler (you can also install VS201X). The installation path is preferably in the form of "X:\ TDM-GCC-64". "X" is the drive letter download address: http://tdm-gcc.tdragon.net/download, or download network disk data, link: http://pan.baidu.com/s/1cMwao2 password: xh9u. After the installation is complete, run the command "mex-setup", which still prompts an error. The problem may be that there is a problem with the path setting of GCC. Choose to call the setenv ('MW_MINGW64_LOC',folder) function to set it, where folder is the path of GCC, for example: setenv (' MW_MINGW64_LOC','D:\ TDM-GCC-64'); run the command and then mex-setup, OK, OK!

C++ files related to Step3:make.m compilation (mainly train and predict source files)

Immediately after Step2, select the current directory as Libsvm, and then run the make script (the current directory is set to Libsvm to prevent scripts with the same name as make in MATLAB). It was thought that it had been successfully integrated, but it still made an error of "No such file or directory." it really felt like fuck dog. Continue to fill the hole and check other blogs. Fortunately, someone has encountered the same problem. The make script file will configure the corresponding lines of code for MATLAB to be modified. Specifically, by changing "CFLAGS" to "COMPFLAGS", you can use ctr+F and then click replace all to be faster. After completing the above operation, run the make script function successfully. In the current folder (.. / Libsvm/matlab), you will find that there are two more .obj files for train and predict. This is the result of compilation, indicating success.

Step4: testing the libsvm environment

In libsvm2.x, there are heart_scale.mat data files, but the latest libsvm3.x only has heart_scale plain text files. This is the format of C++ data files. If you follow the operation in the faruto video and type the "load heart_scale" command, you will find that the result is wrong. This is due to the lack of a file in the corresponding MATLAB data format, so you need to read it with the libsvmread command. This command actually runs a C file of libsvmread.c in lib for data conversion, which is called in the format of libsvmread ('filename'). For example, [label_vector, instance_matrix] = libsvmread ('heart_scale'); the current path used here, I don't know if the absolute path can be used, you can try it, it should be possible. After the data has been transformed, you can find that there are two more data, label_vector and instance, which are sample tags and attributes, respectively. With the data, let's formally test the environment. Call model = svmtrain (label_vector, instance_matrix); after generating the training model, call svmpredict (label_vector, instance_matrix, model,'q') to get the result. I tested the environment with the watermelon data set α 3.0 on Professor Zhou's Machine Learning, and the results are as follows:

Although the result is very poor, but the environment is set up, the test is successful, because I do not have a separate training set and test set, and the data is only about 18, so the result is not meaningful. I just test whether the environment is set up, that's all.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report