Find a fixed accuracy using confusion matrix.
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Aditya Patil
2020-8-19
You can set the random seed to get predictable results, as follows
rng(1234);
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!