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

    %% Fit Optimal Posterior Probability Function Using Holdout Cross Validation
% Platt (2000) outlines a bias-reducing method of estimating the 
% score-to-posterior-probability transformation function.  This method
% estimates the transformation function after the SVM classifer is trained,
% and uses cross validation to reduce bias.  By default, |fitPosterior| and
% |fitSVMPosterior| use 10-fold cross validation when they estimate the
% transformation function.  To reduce run time for larger data sets, you
% can specify to use holdout cross validation instead.
%%
% Load the |ionosphere| data set.

% Copyright 2015 The MathWorks, Inc.

load ionosphere
%%
% Train an SVM classifier. It is good practice to specify the class order
% and standardize the data.
SVMModel = fitcsvm(X,Y,'ClassNames',{'b','g'},'Standardize',true);
%%
% |SVMModel| is a |ClassificationSVM| classifier. The positive class is
% |'g'|.
%%
% Fit the optimal score-to-posterior-probability transformation function.
% For comparison, use 10-fold cross validation (default) and specify a 10%
% holdout test sample.
rng(1); % For reproducibility

tic;    % Start the stopwatch
SVMModel_10FCV = fitPosterior(SVMModel);
toc     % Stop the stopwatch and display the run time

tic;
SVMModel_HO = fitPosterior(SVMModel,'Holdout',0.10);
toc
%%
% Though both runtimes are short because the data set is relatively small,
% |SVMModel_HO| fitted the score tansformation function much faster than
% |SVMModel_10FCV|.