Find a fixed accuracy using confusion matrix.

조회 수: 1 (최근 30일)
sreelekshmi ms
sreelekshmi ms 2020년 4월 19일
답변: Aditya Patil 2020년 8월 19일
I used a confusion matrix to find accuracy. I am getting different accuracy in each run. How can get a fixed accuracy? Anybody, please help me.
clc;
clear;
clc;
clear;
data=readtable('data2.xlsx', 'ReadVariableNames', false);
data.Var1 = findgroups(data.Var1); % convert column
data.Var9 = findgroups(data.Var9); % convert column
minpts=3;
epsilon=30;
data = table2array(data);
[idx, corepts] = dbscan(data,epsilon,minpts);
fig1 = figure();
gscatter(data(:,1),data(:,2),idx);
fig2 = figure();
ax = axes();
hold on;
core=data(corepts, :);
core_idx = idx(corepts, :);
gscatter(core(:,1),core(:,2),core_idx);
centers = splitapply(@(x) mean(x, 1), core, core_idx);
gscatter(centers(:,1), centers(:,2), 1:size(centers,1));
dist2 = (data(:,1) - centers(:,1).').^2 + (data(:,2) - centers(:,2).').^2;
[~,id] = mink(dist2,336,1);
clusters = data(id);
maximum_num_clusters = 7;
Z = linkage(clusters, 'average');
id= cluster(Z, 'Maxclust', maximum_num_clusters);
k = 3;
[idx1,V,D] = spectralcluster(Z,k);
I=data(1:335,9);
[m,order] = confusionmat(I,idx1);
figure
cm = confusionchart(m,order);
c = 3;
TP = cm.NormalizedValues(c,c) ; % true class is c and predicted as c
FP = sum(cm.NormalizedValues(:,c))-TP ; % predicted as c, true class is not c
FN = sum(cm.NormalizedValues(c,:))-TP ; % true class is c, not predicted as c
TN = sum(diag(cm.NormalizedValues))-TP; % true class is not c, not predicted as c
A=(TP+TN)/(TP+TN+FP+FN)*100

답변 (1개)

Aditya Patil
Aditya Patil 2020년 8월 19일
You can set the random seed to get predictable results, as follows
rng(1234);

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by