www.gusucode.com > stats 源码程序 matlab案例代码 > stats/DetermineInSampleClassificationErrorOfSVMClassifiersExample.m
%% Determine the Test Sample Classification Error of SVM Classifiers %% % Load the |ionosphere| data set. % Copyright 2015 The MathWorks, Inc. load ionosphere rng(1); % For reproducibility %% % Train an SVM classifier. Specify a 15% holdout sample for testing. It is % good practice to specify the class order and standardize the data. CVSVMModel = fitcsvm(X,Y,'Holdout',0.15,'ClassNames',{'b','g'},... 'Standardize',true); CompactSVMModel = CVSVMModel.Trained{1}; % Extract the trained, compact classifier testInds = test(CVSVMModel.Partition); % Extract the test indices XTest = X(testInds,:); YTest = Y(testInds,:); %% % |CVSVMModel| is a |ClassificationPartitionedModel| classifier. It % contains the property |Trained|, which is a 1-by-1 cell array holding a % |CompactClassificationSVM| classifier that the software trained using the % training set. %% % Determine how well the algorithm generalizes by estimating the test % sample classification error. L = loss(CompactSVMModel,XTest,YTest) %% % The SVM classifier misclassifies approximately 8% of the test sample % radar returns.