How can I improve the accuracy of my classifier? I tried to remove one of the variables (column 6) but it doesn't help.

2 views (last 30 days)
i have a classifier and after running it the accuracy decreased to 50% from 94% can someone help me to increase the accuracy for future predicitions? Class A is Class X and so on. I want the classifier to confirm this as well. pLease help me to fix this.
%%Training code created April 2023 by M.C.
% Read in table ta from sheet 'ClassA'.
ta = readtable('CLASSES_trainingset.xlsx', 'Sheet', 'ClassA');
% Take columns 3 to 5 and 7 to 12
ta = ta(:, [3:5, 7:12]);
% Read in table tb from sheet 'ClassB'.
tb = readtable('CLASSES_trainingset.xlsx', 'Sheet', 'ClassB');
% Take columns 3 to 5 and 7 to 12
tb = tb(:, [3:5, 7:12]);
% Combine the tables
tPredictors = [ta; tb];
% Create a vector that has the true classes. Class 1 for the top rows (A) and 2 for the lower rows (B)
trueClasses = [ones(height(ta), 1); 2 * ones(height(tb), 1)];
% Setup a session
classificationLearner(tPredictors, trueClasses);
%% Saving Model
save Trained_Model trainedModel051823
Here is the code for the testset
% Load Trained_Model
load Trained_Model;
% Read in table td from sheet sheet1
td = readtable('Classes_testset1.xlsx', 'Sheet', 'ClassX');
% Take just Columns 1 to the end
td = td(:, [3:5, 7:12]);
% Read in table tb from sheet 'ClassB'.
tf = readtable('Classes_testset1.xlsx', 'Sheet', 'ClassY');
% Take just Columns 3 to the end
tf = tf(:, [3:5, 7:12]);
% Combine test sets
Ptests = [td; tf];
% Use model to predict classes
labels = trainedModel051823.predictFcn(Ptests);
% Compare predicted classes to actual classes
trueClasses = [ones(height(td),1); 2 * ones(height(tf),1)];
% Create confusion matrix
figure;
cMat = confusionchart(trueClasses,labels);
% Set confusion matrix title
cMat.Title = 'Confusion Matrix for Classes Test Set';
% Set confusion matrix axes labels
cMat.XLabel = 'Predicted Class';
cMat.YLabel = 'True Class';
% Calculate accuracy
Accuracy = sum(trueClasses == labels) / numel(trueClasses) * 100;
% Determine which class the test set belongs to
if isequal(labels, ones(size(labels)))
disp('This test set belongs to ClassX');
figure; imshow(Ptests);
elseif isequal(labels, 2 * ones(size(labels)))
disp('This test set belongs to ClassY');
figure; imshow(Ptests);
else
disp('This test set does not belong to either Western or Control diet, try fasted');
end
% Display results
Results = table(trueClasses, labels, Ptests);
Thanks!

Answers (0)

Categories

Find more on Data Type Identification in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!