www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TrainAndCrossValidateSupportVectorMachineClassifiersExample.m
%% Train and Cross Validate Support Vector Machine Classifiers %% % Load the |ionosphere| data set. % Copyright 2015 The MathWorks, Inc. load ionosphere %% % Train and cross validate an SVM classifier. It is good practice to % standardize the predictors and specify the order of the classes. rng(1); % For reproducibility CVSVMModel = fitcsvm(X,Y,'Standardize',true,... 'ClassNames',{'b','g'},'CrossVal','on') %% % |CVSVMModel| is not a |ClassificationSVM| classifier, but a % |ClassificationPartitionedModel| cross-validated, SVM classifier. By % default, the software implements 10-fold cross validation. %% % Alternatively, you can cross validate a trained |ClassificationSVM| % classifier by passing it to |crossval|. %% % Inspect one of the trained folds using dot notation. CVSVMModel.Trained{1} %% % Each fold is a |CompactClassificationSVM| classifier trained on 90% of % the data. %% % Estimate the generalization error. genError = kfoldLoss(CVSVMModel) %% % On average, the generalization error is approximately 12%.