www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SpecifyAHoldoutSampleProportionForSVMCrossValidationExample.m
%% Specify a Holdout-Sample Proportion for SVM Cross Validation % By default, |crossval| uses 10-fold cross validation to cross validate an % SVM classifier. You have several other options, such as specifying a % different number of folds or holdout sample proportion. This example % shows how to specify a holdout-sample proportion. %% % Load the |ionosphere| data set. % Copyright 2015 The MathWorks, Inc. load ionosphere rng(1); % For reproducibility %% % Train an SVM classifier. It is good practice to standardize the % predictors and define the class order. SVMModel = fitcsvm(X,Y,'Standardize',true,'ClassNames',{'b','g'}); %% % |SVMModel| is a trained |ClassificationSVM| classifier. |'b'| is the % negative class and |'g'| is the positive class. %% % Cross validate the classifier by specifying a 15% holdout sample. CVSVMModel = crossval(SVMModel,'Holdout',0.15) TrainedModel = CVSVMModel.Trained{1} %% % |CVSVMModel| is a |ClassificationPartitionedModel|. |TrainedModel| is a % |CompactClassificationSVM| classifier trained using 85% of the data. %% % Estimate the generalization error. kfoldLoss(CVSVMModel) %% % The out-of-sample misclassification error is approximately 8%.