?? exp.asv
字號:
%Example: 貝葉斯分類器
% BAYESCLS Bayesian classifier with reject option.
%
% Synopsis:
% [y, dfce] = bayescls(X,model)
%
% Description:
% This function implements the classifier minimizing the Bayesian risk
% with 0/1-loss function. It corresponds to the minimization of
% probability of misclassification. The input vectors X are classified
% into classes with the highest a posterior probabilities computed from
% given model.
%
% The model contains parameters of conditional class probabilities
% in model.Pclass [cell 1 x num_classes] and a priory probabilities
% in model.Prior [1 x num_classes].
%
% The function
% p = feval(model.Pclass{i}.fun, X, model.pclass{i})
% is called to evaluate the i-the class conditional probability of X.
%
% It returns class labels y [1 x num_data] for each input vector
% and matrix dfce [num_class x num_data] of unnormalized a posterior
% probabilities
% dfce(y,i) = Conditional_probability(X(:,i)|y)*Prior(y).
%
% If the field model.eps exists then the Bayesian classifier
% with the reject option is used. The eps is penalty for the
% decision "don't know" which is indicated by label y = 0.
%
% Input:
% X [dim x num_data] Vectors to be classified.
%
% model [struct] Describes probabilistic model:
% .Pclass [cell 1 x num_classes] Class conditional probabilities.
% .Prior [1 x num_classes] A priory probabilities.
%
% .eps [1x1] (optional) Penalty of decision "don't know".
%
% Output:
% y [1 x num_data] Labels (1 to num_classes); 0 for "don't know".
% dfce [num_classes x num_data] Unnormalized a posterior
% probabilities (see above).
trn = load('riply_trn');
subplot(2,2,1);title('訓(xùn)練數(shù)據(jù)集分布');
% 原始分布
ppatterns( trn );
tst = load('riply_tst');
subplot(2,2,2);title('測試數(shù)據(jù)集分布');
% 原始分布
ppatterns( tst );
inx1 = find(trn.y==1);
inx2 = find(trn.y==2);
model.Pclass{1} = mlcgmm(trn.X(:,inx1));
model.Pclass{2} = mlcgmm(trn.X(:,inx2));
% 原始分布
subplot(2,2,3);title('訓(xùn)練數(shù)據(jù)集pgauss分布');
ppatterns( trn );pgauss( model );
% pboundary(model);
model.Prior = [length(inx1) length(inx2)]/(length(inx1)+length(inx2));
ypred = bayescls(tst.X,model);% X=tst.X
cerror(ypred,tst.y)
subplot(2,2,4);title('測試數(shù)據(jù)集pgmm分布');
ppatterns( tst );pgmm( model );
% pboundary(model); % plot decision boundary
% data = load('riply_trn');
% model = mlcgmm( data );
% subplot(2,1,1)
% ppatterns(data); pgauss( model );
% subplot(2,1,2)
% ppatterns(data); pgmm( model );
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -