2023-10-12 23:51:06 +00:00
|
|
|
function [] = Problem1(training_file, test_file)
|
|
|
|
|
|
|
|
% Variables
|
|
|
|
part = {'1' '2' '3'};
|
|
|
|
|
|
|
|
% load data
|
|
|
|
training_data = load(training_file);
|
|
|
|
test_data = load(test_file);
|
|
|
|
|
|
|
|
% Remove label from data
|
|
|
|
training_labels = training_data(:, end);
|
|
|
|
training_data(:, end) = [];
|
|
|
|
test_labels = test_data(:, end);
|
|
|
|
test_data(:, end) = [];
|
|
|
|
|
|
|
|
% Learn prior probabilities
|
|
|
|
pc1 = sum(training_labels==1)/size(training_labels,1);
|
|
|
|
pc2 = 1-pc1;
|
|
|
|
|
|
|
|
for i = 1:length(part)
|
2023-10-25 10:20:44 +00:00
|
|
|
fprintf('Model %s: ', part{i});
|
2023-10-12 23:51:06 +00:00
|
|
|
|
|
|
|
% Training for Multivariate Gaussian
|
2023-10-22 04:32:00 +00:00
|
|
|
[m1, m2, S1, S2] = Param_Est(training_data, training_labels, part(i));
|
2023-10-12 23:51:06 +00:00
|
|
|
[predictions] = Classify(training_data, m1, m2, S1, S2, pc1, pc2);
|
2023-10-25 10:20:44 +00:00
|
|
|
fprintf('(train err = ');
|
2023-10-12 23:51:06 +00:00
|
|
|
Error_Rate(predictions, training_labels);
|
2023-10-25 10:20:44 +00:00
|
|
|
fprintf('), ');
|
2023-10-12 23:51:06 +00:00
|
|
|
|
|
|
|
% Testing for Multivariate Gaussian
|
|
|
|
[predictions] = Classify(test_data, m1, m2, S1, S2, pc1, pc2);
|
2023-10-25 10:20:44 +00:00
|
|
|
fprintf('(test error = ');
|
2023-10-12 23:51:06 +00:00
|
|
|
Error_Rate(predictions, test_labels);
|
2023-10-25 10:20:44 +00:00
|
|
|
fprintf(')\n');
|
2023-10-12 23:51:06 +00:00
|
|
|
end
|
|
|
|
|