classify.m

来自「这个是支持向量聚类机用matlab编译的主程序和部分子程序」· M 代码 · 共 39 行

M
39
字号
%=====================================================================
%
%   Classify
%   ----------------
%
%   Parameters:   
%       classification  - The apriori classifications for each Data point.
%		clusters_assignments -
%		        A vector of the clusters assignments assigned by the algorithm 
%		        to the data points.
%
%	Return Value:
%       maj_class - The classifications assigned by the algorithm to each point.
%       mis_class - The number of errors of the assigned classification against 
%                   the apriori classifications.
%       nof_samples_per_class_per_cluster - as named...
%                   
%   Finds classification to each cluster, according to the majority
%   of apriori classifications of the cluster's data points.
%=====================================================================

function [maj_class, mis_class,nof_samples_per_class_per_cluster] = Classify(classifications, clusters_assignments);

nof_clusters = max(clusters_assignments);

% iterates through the clusters.
for clus_num = 1:nof_clusters
      
    % finds the majority of classifications in the current cluster.
    classification_per_cluster = classifications(find(clusters_assignments == clus_num));
    unique_classifications = unique(classifications);
    for i = 1:length(unique_classifications)
        nof_samples_per_class(i) = length(find(classification_per_cluster==unique_classifications(i))); 
    end
   
    nof_samples_per_class_per_cluster(clus_num,:) = nof_samples_per_class; 
     
    [max_rep,max_index] = max(nof_samples_per_class); 
    maj_class(clus_num) = unique_classifications(max_index);
    mis_class(clus_num) = sum(nof_samples_per_class) - max_rep;
    
    
end

⌨️ 快捷键说明

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