MATLAB Answers

KNN classification accuracy problem

54 views (last 30 days)
Balaji M. Sontakke
Balaji M. Sontakke on 17 Feb 2020
In my program accuracy is not increases I have given properly traning and testing input to knn classifier. I got following result, how I increase the accuracy rate?
Accuracy: 0.1125
Error: 0.8875
Sensitivity: 0.1125
Specificity: 0.9533
Precision: 0.1101
FalsePositiveRate: 0.0467
F1_score: NaN
MatthewsCorrelationCoefficient: 0.1179
Kappa: 0.8930
clear all;
clc;
%% BUILD DORSAL HAND VEIN TEMPLATE DATABASE
tic; %% calculating elapsed time for execution
%% load mat files
load('db1.mat');
load('db2.mat');
%% reshape into row vector for 100 classes
%% reshape into row vector for 10 classes
reduced_testdata = reshape(reduced_testdata,1,2,40); % one row,four column and 15(60/4) group for 20 classes
reduced_traindata = reshape(reduced_traindata,1,2,80); % one row,four column and 45(180/4) group for 20 classes
%% adjust dimension
% Adjust matrix dimension
P_test = cell2mat(reduced_testdata); % Convert cell array to matrix
P_train = cell2mat(reduced_traindata);
%% rearranges the dimensions of P_test and P_train
C = permute(P_test,[1 3 2]);
P_test = reshape(C,[],size(P_test,2),1);
C = permute(P_train,[1 3 2]);
P_train = reshape(C,[],size(P_train,2),1);
%% labeling class
train_label=load('train_label.txt');
test_label=load('test_label.txt');
%%% Normalisation
% P_train=P_train/256;
% P_test=P_test/256;
% Normalisation by min max
%
P_train=mapminmax(P_train,0,1);
P_test=mapminmax(P_test,0,1);
% Normalisation by Z - Scores
%
% P_train = zscore(P_train,0,2);
% P_test =zscore(P_test,0,2);
%'euclidean'; 'cityblock'; 'chebychev'; 'minkowski'; 'cosine'; 'correlation'; 'spearman'; 'hamming'; 'jaccard'; 'squaredeuclidean'
predictlabel = knnclassify(P_test, P_train, train_label,1,'euclidean','nearest');
%
cp = classperf(test_label,predictlabel);
% % % % %
Conf_Mat = confusionmat(test_label, predictlabel);
disp(Conf_Mat);
%
%
% disp('_____________Multiclass demo_______________')
% disp('Runing Multiclass confusionmat')
%
[c_matrix,Result,RefereceResult]= confusion.getMatrix(test_label,predictlabel);
%% calculating elapsed time for execution
toc

  0 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!