How to apply NMI (mutualinfo) accuracy measure for classifiers?
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to compute the NMI measure for obtaining the accuracy of the classifiers on a dataset (attached) I used this mutualinfo function for this purpose.
function I = mutualinfo(L1,L2)
%MUTUALINFO Mutual information.
% I = MUTUALINFO(L1,L2) returns the mutual information shared by two N-by-1
% integer arrays of classification data, L1 and L2.
%
% Copyright (2009) Sandia Corporation. Under the terms of Contract
% DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
% certain rights in this software.
N = length(L1);
k1 = unique(L1);
k2 = unique(L2);
I = 0;J=0;K=0;
% loop over the unique elements of L1
for i = 1:size(k1,1)
% loop over the unique elements of L2
for j = 1:size(k2,1)
% the mutual probability of two classification indices occurring in
% L1 and L2
pij = sum((L1 == k1(i)).*(L2 == k2(j)));%/N;
% the probability of a given classification index occurring in L1
pi = sum(L1 == k1(i));%/N;
% the probability of a given classification index occurring in L2
pj = sum(L2 == k2(j));%/N;
if (pij > 0)
I = I + pij*log((N*pij)/(pi*pj));
In this code I used three classifiers for the data, then I used the mutualinfo function to have the accuracies of 3 classifiers.
clear
close all
clc
load databs1.mat;
data=databs1;
[n,m]=size(data);
rows=(1:n);
test_count=floor((1/6)*n);
sum_ens=0;sum_result=0;
test_rows=randsample(rows,test_count);
train_rows=setdiff(rows,test_rows);
test=data(test_rows,:);
train=data(train_rows,:);
xtest=test(:,1:m-1);
ytest=test(:,m);
xtrain=train(:,1:m-1);
ytrain=train(:,m);
%-----------svm------------------
svm=svm1(xtest,xtrain,ytrain);
%-------------random forest---------------
rforest=randomforest(xtest,xtrain,ytrain);
%-------------decision tree---------------
DT=DTree(xtest,xtrain,ytrain);
%---------------bayesian---------------------
NBModel = NaiveBayes.fit(xtrain,ytrain, 'Distribution', 'kernel');
Pred = NBModel.predict(xtest);
dt=Pred;
tt1=mutualinfo(svm,ytest); %svm
tt2=mutualinfo(rforest,ytest); %random forest
tt3=mutualinfo(dt,ytest); %Naive Bayes
disp('accuracy of svm:');
disp(tt1);
disp('accuracy of random forest:');
disp(tt2);
disp('accuracy of Naive Bayes:');
disp(tt3);
But the resault is 0 for two of them and It’s not right to have zero accuracy.
accuracy of svm:
0
accuracy of random forest:
0.3803
accuracy of NaveBayes:
0
I’ll be gatefull to have your opinions how to use NMI measure for computing accuracy of a classifier. Does this code have any problems to be fixed.
Thank you very much for your valuable opinions.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Classification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!