⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp.asv

📁 支持向量机工具箱
💻 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('训练数据集分布');
  % 原始分布
   ppatterns( trn );
  tst = load('riply_tst');
  subplot(2,2,2);title('测试数据集分布');
  % 原始分布
   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('训练数据集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('测试数据集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 );
 
 
 
 
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -