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 Center および File ExchangeStatistics 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