www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimateScoreTransformationFunctionForInseparableClassesExample.m
%% Fit the Score-to-Posterior Probability Function for Separable Classes %% % Load Fisher's iris data set. Train the classifier using the petal % lengths and widths, and remove the virginica species from the data. % Copyright 2015 The MathWorks, Inc. load fisheriris classKeep = ~strcmp(species,'virginica'); X = meas(classKeep,3:4); y = species(classKeep); gscatter(X(:,1),X(:,2),y); title('Scatter Diagram of Iris Measurements') xlabel('Petal length') ylabel('Petal width') legend('Setosa','Versicolor') %% % The classes are perfectly separable. Therefore, the score transformation % function is a step function. %% % Train an SVM classifier using the data. Cross validate the classifer % using 10-fold cross validation (the default). rng(1); CVSVMModel = fitcsvm(X,y,'CrossVal','on'); %% % |CVSVMModel| is a trained |ClassificationPartitionedModel| SVM % classifier. %% % Estimate the step function that transforms scores to posterior % probabilities. [ScoreCVSVMModel,ScoreParameters] = fitSVMPosterior(CVSVMModel); %% % |fitSVMPosterior| does the following: % % * Uses the data that the software stored in |CVSVMModel| to fit the % transformation function % * Warns whenever the classes are separable % * Stores the step function in |ScoreCSVMModel.ScoreTransform| % %% % Display the score function type and its parameter values. ScoreParameters %% % |ScoreParameters| is a structure array with four fields: % % * The score transformation function type (|Type|) % * The score corresponding to the negative class boundary (|LowerBound|) % * The score corresponding to the positive class boundary (|UpperBound|) % * The positive class probability (|PositiveClassProbability|) % %% % Since the classes are separable, the step function transforms the score % to either |0| or |1|, which is the posterior probability that an observation is a % versicolor iris.