Mathematical modeling (10)--MATLAB application of support vector machine

Source: Internet
Author: User
Tags constant

For a total of M samples, each sample has n indicators, according to some of the existing sample values to speculate on the category of other samples of such a problem, you can use a routine to transpose the matrix, the row represents the indicator, the column represents the sample extracted from the classified sample and the unclassified samples are standardized to obtain the classified sample category symbol (group) Classification function weight coefficients and constant terms calculation of the rate of error (validation of classified samples) to the Unclassified sample 1

% support Vector machine
CLEAR,CLC
a0=load (' fenlei.txt ');
A=a0 ';% sorted by Category City
Yi=a (:, [1:27]);  % extracted classified Cities
dai=a (:, [28:end]);% extract to be classified City
[Yy,ps] = Mapstd (yi);% normalized
dd = mapstd (' Apply ', dai,ps);% To classify data standardization
group = [Ones (20,1); 2*ones (7,1)];% the class symbol for the known sample
s = Svmtrain (yy ', group), and% training support vector machine classifier
Sv_index = S. supportvectorindices;% the support vector  returns the city number
beta = s.alpha;% returns the weight coefficient of the classification function
BB = s.bias;% Returns the constant term of the categorical function
Mean_ And_std_trans = s.scaledata;% The first line returns the opposite number of known vectors for a known sample, the second line is the reciprocal check of the standard deviation vector
= svmclassify (s,yy ');% verifies the known sample point
err_ Rate = 1-sum (group==check)/length (group),% calculation of the error rates of known sample points
solution = svmclassify (S,DD ');% treatment of sample points classification
%svmtrain Training support Vector machine classifier function
%svmclassify  using support vector machine classification function
%svmsmoset  specifying the sequence minimization parameter function used by the support vector machine function
Example 2

% raw data cancerdata.txt can be downloaded online, the data of b replaced by 1,m replaced with -1,x replaced by 2, deleted the separator *, the replacement of the data named Cancerdata2.txt
clc,clear
a0=load (' Cancerdata2.txt ');
A0 (:, 1) =[];  % delete the first column case number
a=a0 ';% transpose the original data
yi=a ([2:end],[1:500]);% presents data dai=a of known sample points
([2:end],[501:end]);% proposed data
to be classified [Yy,ps]=mapstd (Yi); % classified Data standardized
 DD=MAPSTD (' Apply ', dai,ps),% to be classified data standardized
 Group=a (1,[1:500]);% known sample point category designator
Group=group ';
S=svmtrain (YY ', group, ' Method ', ' SMO ', ' kernel_function ', ' quadratic '); % use the sequence minimization method to train support vector machine classifier, if using two times programming method to train support vector machine can not solve
sv_index=s.supportvectorindices '  % return support Vector label
beta= S.alpha ';  % returns the weight coefficient of the classification function
B=s.bias;  % returns the constant term of the classification function
mean_and_std_trans=s.scaledata; The 1th line returns the opposite number of the known sample point mean vector, and the 2nd line returns the reciprocal check=svmclassify of the standard deviation vector
(s , yy ');  % validation known sample point
err_rate=1-sum (Group==check)/length (group),% calculation
of the wrong rate solution=svmclassify (S,DD ');% of sample points to be classified
solution=solution '; 
Sg=find (solution==1);  % The benign number Sb=find (Solution==-1) in the sample points to be judged,
and the number of malignant numbers in the sample points to be judged

Example code and data download address http://download.csdn.net/download/qq_32589267/9935177

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.