MATLAB聚類有效性評價指標(外部 成對度量)

MATLAB聚類有效性評價指標(外部 成對度量)

做者:凱魯嘎吉 - 博客園 http://www.cnblogs.com/kailugaji/html

更多內容,請看:MATLAB: Clustering Algorithms, MATLAB聚類有效性評價指標(外部)post

前提:數據的真實標籤已知!TP:真陽性,FP:假陽性,FN:假陰性,TN:真陰性lua

1. MATLAB程序

function result = Evaluate(real_label,pre_label)
% This fucntion evaluates the performance of a classification model by 
% calculating the common performance measures: Accuracy, Sensitivity, 
% Specificity, Precision, Recall, F-Measure, G-mean.
% Input: ACTUAL = Column matrix with actual class labels of the training
%                 examples
%        PREDICTED = Column matrix with predicted class labels by the
%                    classification model
% Output: EVAL = Row matrix with all the performance measures
% https://www.mathworks.com/matlabcentral/fileexchange/37758-performance-measures-for-classification

idx = (real_label()==1);

p = length(real_label(idx));
n = length(real_label(~idx));
N = p+n;

tp = sum(real_label(idx)==pre_label(idx));
tn = sum(real_label(~idx)==pre_label(~idx));
fp = n-tn;
fn = p-tp;

tp_rate = tp/p;
tn_rate = tn/n;

accuracy = (tp+tn)/N; %準確度
sensitivity = tp_rate;  %敏感性:真陽性率
specificity = tn_rate; %特異性:真陰性率
precision = tp/(tp+fp);  %精度
recall = sensitivity;  %召回率
f_measure = 2*((precision*recall)/(precision + recall));  %F-measure
gmean = sqrt(tp_rate*tn_rate); 
Jaccard=tp/(tp+fn+fp); %Jaccard係數

result = [accuracy sensitivity specificity precision recall f_measure gmean Jaccard];
fprintf('accuracy=%.4f, sensitivity=%.4f, specificity=%.4f, precision=%.4f, recall=%.4f, f_measure=%.4f, gmean=%.4f, Jaccard=%.4f\n', ...
    accuracy, sensitivity, specificity, precision, recall, f_measure, gmean, Jaccard);

2. 結果

>> A = [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3];
>> B = [1 2 1 1 1 1 1 2 2 2 2 3 1 1 3 3 3];
>> result = Evaluate(A,B)
accuracy=0.7059, sensitivity=0.8333, specificity=0.6364, precision=0.5556, recall=0.8333, f_measure=0.6667, gmean=0.7282, Jaccard=0.5000

result =

   0.705882352941177   0.833333333333333   0.636363636363636   0.555555555555556   0.833333333333333   0.666666666666667   0.728219081254419   0.500000000000000

3. 參考

[1] MATLAB聚類有效性評價指標(外部)url

[2] 類似性度量spa

[3] Performance Measures for Classificationorm

[4] Gaussian field consensus論文解讀及MATLAB實現htm

相關文章
相關標籤/搜索