MATLAB call and cross-verification of libsvm

Source: Internet
Author: User
Tags svm

I heard a lecture from a senior engineer and found that I have been very poor in scientific research, mainly in the following aspects, (I am also proposing to urge myself to avoid these problems in the future)

1. There is always no end to doing things, so that the knowledge points cannot be thoroughly understood at a time. Only when the same knowledge point is used at a time can we find that we still don't fully understand this knowledge.

2. I am not good at summing up. I have done a lot of things (such as code and papers), but I have not recorded every job, which makes it difficult to clarify what I have done before.

3. Poor retrieval capabilities, resulting in a long time to find the required information.

4. There are too few documents to read, so it is difficult to put forward new ideas and opinions.

The above four points are the main areas I think we need to improve in scientific research and work. I have also improved them one by one from now on. I hope that I will develop good habits one month later, so that the above defects can be corrected.

The following is the first improvement: SVM has been in contact for a long time and has been studied and used in both theory and code. Due to the large amount of online data, I am too lazy to sort it out, baidu and Google solve each problem. However, if someone asks me the specific content, it is difficult for me to answer the question. After all, others' things are others, it doesn't mean you have mastered it. Only the knowledge you have mastered is your own. You can communicate with others and put forward your own opinions.

I. How to use MATLAB to call SVM

The main reason for my introduction is that we use the most tools for machine vision algorithms, while the SVM toolbox in MATLAB can only be used in two categories, in addition, it is not possible to select appropriate parameters for cross-validation. However, during normal use, it is inevitable to encounter multiple types of problems, and selecting appropriate parameters is also very important for SVM. The following describes how to download libsvm and configure the MATLAB environment.

Main reference home page: http://blog.csdn.net/abcjennifer/article/details/7370177

1. Reference website:

Libsvm library download: http://www.csie.ntu.edu.tw /~ Cjlin/libsvm/, http://www.matlabsky.com/thread-9327-1-1.html (faruto, recommended)

Http://v.youku.com/v_showMini/id_XMjc2NTY3MzYw_ft_131.html video

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

2. Configure the MATLAB environment

A. Set path

File-> set path-> Add with subfolders-> Add path to the libsvm-3.11 folder

B. Compile in MATLAB

Objective: To compile C ++ files in libsvm-3.11 \ MATLAB, such as libsvmwrite. C, into MATLAB files such as libsvmread. mexw32, so that it can be directly called in command window.

The operations are as follows: 1. Mex-Setup

 

Please choose your compiler for Building external interface (MEX) files:

Wocould you like Mex to locate installed compilers [y]/n? Y

Please choose your compiler for Building external interface (MEX) files:

Wocould you like Mex to locate installed compilers [y]/n? Y
Select a compiler:
Lcc-win32 C 2.4.1 In D: \ MATLAB ~ 1 \ sys \ KP
[2] Microsoft Visual C + + 6.0 in D: \ Microsoft Visual Studio

[0] None

Compiler: (the differences between different versions of MATLAB and the Self-installed compiler are different. Therefore, you only need to select the compiler you have installed)

 

Compiler: 2

Please verify your choices:

Compiler: Microsoft Visual C + + 6.0
Location: D: \ Microsoft Visual Studio

Are these correct [y]/n? Y

Trying to update options file: C: \ Users \ faruto \ appdata \ roaming \ Mathworks \ MATLAB \ r2009b \ mexopts. bat
From template: D: \ MATLAB ~ 1 \ bin \ Win32 \ mexopts \ msvc60opts. bat

Done...

 

2. Make

Make

In this process, you must switch the path to the MATLAB path so that you can call the make function to make.

All the notes mentioned above have been pointed out, and I have also tested them in the field of "maid" and "vs2010.

After the operation, you can use the ready-made dataset heart_scale to test it. Accuracy = 86.6667% (234/270) (Classification) appears)

1 load(‘heart_scale‘)2 model = svmtrain(heart_scale_label,heart_scale_inst);  3 [predict_label,accuracy] = svmpredict(heart_scale_label,heart_scale_inst,model); 

The 'heart _ scale' built-in mat file in libsvm.

Ii. How to optimize parameters

Reference URL: Workshop.

1 %添加参数寻优代码2 [bestacc,bestc,bestg] = SVMcg(heart_scale_label,heart_scale_inst,-9,9,-1,1,5,1,1);

Because this test case is not standardized, it cannot reflect the advantages of parameter optimization.

The above is the experiment part. Through a small experiment, we can have a rough understanding of SVM, and at the same time promote our own motivation to learn theory, therefore, the following blog will mainly introduce SVM theory, Because SVM theory is also introduced a lot, so I will mainly sort out the good reference content, at the same time, write your own experiences and understandings to facilitate your own viewing and communication.

 

MATLAB call and cross-verification of libsvm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.