How to add a SVM function toolbox in MATLAB

Source: Internet
Author: User
Tags svm

Purpose: Svm_stevegunn added to my MATLAB toolbox

Tools/Materials: Matlab 2013B, SVM Toolbox

Operation Steps:

1. Download the SVM Toolkit

Address: http://www.pudn.com/downloads343/sourcecode/math/detail1499382.html

2, unpack the toolkit to E:\matlab\toolbox, you can also extract the name after the copy of the past. (Installation directory)

3, open the MATLAB click Set path---->add folder (you can also choose the following addwithsubfolder) and then add your Toolbox folder in it, save.

4, refresh the path, this step must be done, the path added in the File→preferences→general Toolbox path caching Click Update Toolbox path cache updated.

5, verify whether to add the success, finally in the command bar of MATLAB input which svcoutput can see the path E:\matlab\toolbox\svm\svcoutput.m on it.

6. Call the Toolbox:

How to use SVM for classification
1) Enter the necessary parameters in MATLAB: X,Y,KER,C,P1,P2
The data I took in the test was:
N = 50;
N=2*n;
RANDN (' state ', 6);
X1 = RANDN (2,n)
Y1 = ones (1,n);
x2 = 5+randn (2,n);
y2 =-ones (1,n);
Figure
Plot (x1 (1,:), X1 (2,:), ' bx ', x2 (1,:), X2 (2,:), ' K. ');
Axis ([-3 8-3 8]);
Title (' C-svc ')
Hold on;
X1 = [X1,X2];
Y1 = [Y1,y2];
X=x1 ';
Y=y1 ';
where x is the matrix of 100*2 and Y is the matrix of 100*1
C=inf;
Ker= ' linear ';
Global P1 P2
p1=3;
P2=1;
Then, enter in MATLAB: [nsv alpha bias] = svc (x,y,ker,c), after carriage return, the display:

Support Vector Classification
_____________________________
Constructing ...
Optimising ...
Execution time:1.9 seconds
Status:optimal_solution
|w0|^2:0.418414
margin:3.091912
Sum alpha:0.418414
Support Vectors:3 (3%)
NSV =
3

Alpha =
0.0000
0.0000
0.0000
0.0000
0.0000
2) Input prediction function, can be compared with the expected classification results.
Input: Predictedy = Svcoutput (X,y,x,ker,alpha,bias), get after carriage return:

Predictedy =
1
1
1
1
1
1
1
1
1
3) Drawing
Input: Svcplot (x,y,ker,alpha,bias), enter

Add:
X and Y are data, m*n:m is the number of samples, n is the number of eigenvectors
For example: Take 20 sets of training data x,10 Group has a fault, 10 groups without fault, each training data has 13 characteristic parameters, then m=20,n=13
Y is the matrix of 20*1, where 10 groups are 1 and 10 groups are-1.
For test data, if 6 sets of test data are taken, 3 groups are faulty, and 3 groups are not faulted, then m=6,n=13
Y, M=6,n=1

problems that may occur:

1. Today I am using the SVM Generic toolbox to classify the signal data of the eye, the following error occurred:

Support Vector Classification
_____________________________
Constructing ...
Optimising ...
??? Dimension Error (ARG 3 and later).

Error in ==> Svc at 60
[Alpha lambda how] = QP (H, C, A, B, VLB, Vub, x0, neqcstr);

I don't know what the reason is.

A: This morning finally found the reason for this error: It is not the problem of the SVM program, I was in the collation of the sample, the parameters needed to reverse the row and column.

Here x is the sample feature (row vector) and Y is the category of the corresponding sample (one row for x is a row of samples).

2. using the first Steve Gunn ' s SVM encountered a problem.
??? Invalid mex-file ' Xxxx\svm\qp.dll ': The specified procedure could not being found.

??? Invalid mex-file ' D:\Program files\matlab\r2007a\toolbox\svm\qp.dll ': The specified program could not be found.
Error in ==> Svc at 60
[Alpha lambda how] = QP (H, C, A, B, VLB, Vub, x0, neqcstr);

This problem is caused by the version problem, I use the MATLAB version R2007. I'm trying to find a solution to see if I can recompile the qp.dll.
Check out the information for one night and finally find out how to solve this simple problem. The key is not to look carefully at first.

Problem:??? Invalid mex-file ' D:\Program files\matlab\r2007a\toolbox\svm\qp.dll ': The specified program could not be found.
Problem Description: Mex compiles results under different Windows OS, so we need to recompile qp.dll
Method: There is a optimiser folder under Steve Gunn's package to change the current diretory directory to optimiser directory, for example D:\Program files\matlab\r2007a\toolbox\svm\ Optimiser, and then run the command
>> mex-v qp.c pr_loqo.c
After the command is finished, you will find that the original Qp.dll changed to Qp.dll.old, and qp.mexw32, we changed the file to Qp.dll copy to the Toolbox folder. Original Toolbox file Qp.dll can change the name first .... (Frysoo@hotmail.com)

This problem has been solved ...
I ran the following file through (the file was searched from the web, the author did not verify, thanks to the original author).
N = 50; N=2*N;RANDN (' state ', 6); X1 = RANDN (2,n); Y1 = ones (1,n); x2 = 5+randn (2,n); y2 =-ones (1,n);
Figure;plot (x1 (1,:), X1 (2,:), ' bx ', x2 (1,:), X2 (2,:), ' K. '); axis ([-3 8-3 8]); Title (' C-svc ')
Hold on; X1 = [X1,X2];   Y1 = [Y1,y2]; X=x1 '; Y=y1 '; C=inf; Ker= ' linear ';
Global P1 P2 p1=3; P2=1;
[NSV alpha Bias] = svc (x,y,ker,c)






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.