error in knn classification train accuracy is 96.33% but test accuracy is only 7.33%, is this overfitting problem.
1 回表示 (過去 30 日間)
古いコメントを表示
error in knn classification train accuracy is 96.33% but test accuracy is only 7.33%, is this overfitting problem. how to solve this following is the code..
clear all; clc;
%% BUILD DORSAL HAND VEIN TEMPLATE DATABASE %build_db(10,8); %THIS WILL TAKE ABOUT 30 MINUTES
% % % load mat files load('db1.mat'); load('db2.mat'); %% reshape into row vector
reduced_testdata = reshape(reduced_testdata,1,5,16); % reduced_traindata = reshape(reduced_traindata,1,5,32); %
%% adjust dimension % reduced_testdata = reduced_testdata'; % Adjust matrix dimension P_test = cell2mat(reduced_testdata); % Convert cell array to matrix
%reduced_traindata = reduced_traindata'; P_train = cell2mat(reduced_traindata);
%%rearranges the dimensions of P_test and P_train so that they %are in the order specified by the vector ORDER.
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;
%% classfication
predictlabel = knnclassify(P_test, P_train, train_label,3,'euclidean','random'); cp = classperf(test_label,predictlabel);
% Evaluation performance disp('_____________Multiclass demo_______________') disp('Runing Multiclass confusionmat')
[FPR, TPR,Thr, AUC, OPTROCPT] = perfcurve(predictlabel, test_label,1)
figure,
plot(TPR,FPR,'r-','LineWidth',4);
xlabel('False positive rate')
ylabel('True positive rate')
title('ROC Curve for Classification ')
Tbl = table(FPR, TPR,Thr)
%% FAR = FPR = FP/(FP + TN) and FRR = FNR = FN/(FN + TP)
[FPR, FNR,Thr] = perfcurve(predictlabel, test_label,1,'xCrit','FPR','yCrit','FNR','TVals','all') Thr = Thr/10; figure, plot(Thr,FPR,'r--','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10); xlabel('Threshold') ylabel('False positive rate / FAR') title('ROC Curve for Classification ')
figure, plot(Thr,FNR,'r--','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10); xlabel('Threshold') ylabel('False Negative rate / FRR') title('ROC Curve for Classification ') Tbl = table(FPR, FNR)
cp.CorrectRate*100 dca = predictlabel==test_label; peracc = sum(dca)/length(dca)*100; fprintf('\n\n Overall accuracy:%f%%\n',peracc);
1 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!