Find a fixed accuracy using confusion matrix.

14 vues (au cours des 30 derniers jours)
sreelekshmi ms
sreelekshmi ms le 19 Avr 2020
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

Réponses (1)

Aditya Patil
Aditya Patil le 19 Août 2020
You can set the random seed to get predictable results, as follows
rng(1234);

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by