csci5521/assignments/hwk01/HW1_script.m

29 lines
1.2 KiB
Mathematica
Raw Normal View History

2023-10-01 23:09:50 +00:00
% solves question 1d, Print a table of error rate of each prior on the
% validation set and the error rate using the best prior on the test set.
% use functions MLE_Learning.m, Bayes_Learning.m, Bayes_Testing.m
% load data
load('training_data.txt');
load('validation_data.txt');
load('testing_data.txt');
%Part 1: using the first two columns to test MLE_Learning and Bayes_Testing
%function
training2_data = training_data(:,[1,2,end]);
testing2_data = testing_data(:,[1,2,end]);
[p1,p2,pc1,pc2] = MLE_Learning(training2_data);
test_error = Bayes_Testing(testing2_data, p1, p2, pc1, pc2); % use parameters to calculate test error
%Part 2: using the compmlete dataset to test MLE_Learning
[p1,p2,pc1,pc2] = MLE_Learning(training_data);
test_error = Bayes_Testing(testing_data, p1, p2, pc1, pc2); % use parameters to calculate test error
%Part 3: using validataion set to do Bayes_Learning
[p1,p2,pc1,pc2] = Bayes_Learning(training_data, validation_data); % get p1, p2, pc1, pc2
[pc1,pc2] %show the best prior
test_error = Bayes_Testing(testing_data, p1, p2, pc1, pc2); % use parameters to calculate test error
% by calling Bayes_Learning and Bayes_Testing, the error table of
% validataion data and test data error is automatically printed to command
% window