a=xlsread('D:\homework\精度验证产品.xlsx');
Predicted=a(:,1);
val=a(:,2);
g=0;
for i=1:size(a,1) %记录验证结果是否与实际值一致
if(Predicted(i)==val(i))
g=g+1;
end
end
OA=g/(size(a,1));
% 计算混淆矩阵
confusion_matrix = confusionmat(val, Predicted);
% 计算总样本数
total_samples = sum(sum(confusion_matrix));
% 计算实际一致的样本数
actual_agreement = sum(diag(confusion_matrix));
% 计算预期一致的样本数
expected_agreement = sum(sum(confusion_matrix, 2) .* sum(confusion_matrix, 1)) / total_samples;
% 计算Kappa系数
kappa_coefficient = (actual_agreement - expected_agreement) / (total_samples - expected_agreement);
fprintf('Kappa系数: %.2f\n', kappa_coefficient);