load("savedPumpData.mat");
disp(pumpData);
Data = removevars(pumpData,"flow");
save("Data.mat","Data");
disp(Data)
trainRatio = 0.7;
% Create a random partition of the data into training and test sets
c = cvpartition(size(Data, 1), 'HoldOut', 1 - trainRatio);
% Create the training and test sets
trainingData = Data(c.training, :);
testData = Data(c.test, :);
[featureTableTrain,outputTable0] = Features(trainingData);
disp(featureTableTrain)
[trainedClassifier, validationAccuracy] = BagTrees(featureTableTrain);
[featureTableTest,outputTable] = Features(testData);
disp(featureTableTest)
[yfit,scores] = BaggedTress.predictFcn(featureTableTest);
disp(yfit);
accuracy = sum(yfit==testData.faultCode)/numel(testData.faultCode)*100;
fprintf('Accuracy: %.2f%%\n', accuracy);
figure;
confusionchart(testData.faultCode, yfit);
title('Confusion Matrix RF');
[yfit1,scores1] = trainedClassifier.predictFcn(featureTableTest);
disp(yfit1);
accuracy = sum(yfit1==testData.faultCode)/numel(testData.faultCode)*100;
fprintf('Accuracy: %.2f%%\n', accuracy);
figure;
confusionchart(testData.faultCode, yfit1);
title('Confusion Matrix');
%Feature is the function code generated using Diagnostic feature designer
%BaggedTrees is the model exported to workspace using classification learner getting 90% accuracy
%BagTrees is the generated function code of the same model which is exported getting 70%