www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimateClassificationEdgeOfTrainedSVMModelExample.m

    %% Estimate the Test Sample Edge 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 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.
%%
% Estimate the test sample edge.
e = edge(CompactSVMModel,XTest,YTest)
%%
% The estimated test sample margin average is approximately 5.