MATLAB SVM 代码详细学习(1)

fitcecoc : 用于SVM多分类

Mdl =fitcecoc(tbl,ResponseVarName) 使用tbl中的预测器和tbl中的类标签返回完整的、经过训练的纠错输出代码(ECOC)多类模型。fitcecoc使用K(K-1)/2二进制支持向量机(SVM)模型,使用一对一编码设计,其中K是唯一类标签(层级)的数目。Mdl是一种分类ECOC模型。

Mdl =fitcecoc(tbl,formula) 使用表tbl中的预测器返回ECOC模型。类标签公式是一个公式字符串,它标识用于训练的tbl中的响应和预测器变量。

Mdl是一种分类ECOC模型。默认情况下,fitcecoc使用SVM二进制学习者,并使用一对一的编码设计。可以使用点标记访问Mdl属性。

 
%% Train a Multiclass Model Using SVM Learners使用SVM学习者训练多类模型
% Train an error-correcting output codes (ECOC) multiclass model using 
% support vector machine (SVM) binary learners.训练纠错输出码(ECOC)多类模型 
% Load Fisher's iris data set.加载Fisher的虹膜数据集。


load fisheriris 
X = meas; 
Y = species;


% Train an ECOC multiclass model using the default options. 

Mdl = fitcecoc(X,Y)

% |Mdl| is a |ClassificationECOC| model.  By default, |fitcecoc| uses SVM 
% binary learners, and uses a one-versus-one(一对一) coding design. You can access
% |Mdl| properties using dot notation. 

% Display the coding design matrix. 

Mdl.ClassNames CodingMat = Mdl.CodingMatrix

% You can access each binary learner using cell indexing and dot notation.
 %您可以使用单元格索引和点标记访问每个二进制学习器。 
Mdl.BinaryLearners{1}               % The first binary learner 
Mdl.BinaryLearners{1}.SupportVectors % Support vector indices 

%% % Compute the in-sample classification error. 

isLoss = resubLoss(Mdl) 

%% % The classification error is small, but the classifier might have been 
% overfit.  You can cross validate the classifier using |crossval|.

猜你喜欢

转载自blog.csdn.net/qq_42463478/article/details/80700790