clear; clc; close all; load('params/materials_names') load('params/names') %% This script has to be ONLY used to test the generalization abilities %% So, use this script only if you plan to train on one or more materials and test on DIFFERENT materials. %% If you need to train and test on the same materials, use the other script: Prediction.m %% Params nTrees = 5000; categories = [1,2,4,5]; %% Database to Train materials = [1,3]; [DataTrain, ~, labelTrain, ~] = dataBaseLoader(categories, materials); %% Database to Test materials = [2]; [~, DataTest, ~, labelTest] = dataBaseLoader(categories, materials); %% Training disp('I am Training') B = TreeBagger(nTrees,DataTrain,labelTrain, 'Method', 'classification'); disp('Training finished') %% Testing disp('I am testing') predChar1 = B.predict(DataTest); % Predictions is a char though. We want it to be a number. predictedClass = str2double(predChar1); accuracy=sum(predictedClass==labelTest)/length(labelTest); disp("Accuracy: ") disp(accuracy) %% cm = confusionchart(labelTest,predictedClass); cm.NormalizedValues fig = figure; cm = confusionchart(labelTest,predictedClass,'RowSummary','row-normalized','ColumnSummary','column-normalized'); %Resize the container of the confusion chart so percentages appear in the row summary. fig_Position = fig.Position; fig_Position(3) = fig_Position(3)*1.5; fig.Position = fig_Position;