-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.m
More file actions
114 lines (84 loc) · 3.09 KB
/
Project.m
File metadata and controls
114 lines (84 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
clc
clear
close all
load('data.mat')
% Step 1 : Training: Use the data of the first 100 subjects to estimate
% mean and variance of F1 and F2
f1_train = F1(1:100,:);
f2_train = F2(1:100,:);
f1_test = F1(101:1000,:);
f2_test = F2(101:1000,:);
mean_vals(1,:) = mean(f1_train,1);
var_vals(1,:) = var(f1_train,1);
mean_vals(2,:) = mean(f2_train,1);
var_vals(2,:) = var(f2_train,1);
% Step 2 : Testing: Assume that X = F1. Using the Bayes' theorem,
% calculate the probability of each class for data of the remaining
% subjects (columns 101-1000 of F1) and consequently predict the class
% for each data point.
% Note that each subject performed 5 different tasks so you need to predict
% the class of 4500 data points.
% Step 2.2.Calculating the accuracy of the classifier: You need to check
% the percentage of the data whose class are correctly predicted.
% Classification accuracy = correct predictions / total predictions
% Error rate = incorrect predictions / total predictions
%[z,p] = classifier(f1_test,mean_vals(1,:),var_vals(1,:));
[z_F1,p_F1,I_F1] = classifier1(f1_test,mean_vals(1,:),var_vals(1,:));
actual = zeros(900, 5);
actual(:,1) = 1;
actual(:,2) = 2;
actual(:,3) = 3;
actual(:,4) = 4;
actual(:,5) = 5;
error_mat_F1 = actual - I_F1;
idx_F1=error_mat_F1==0; %returns 1 at position where value is zero and zeros everywhere else
error_F1=sum(idx_F1(:));
Correction_Rate_F1 = error_F1/4500;
Error_Rate_F1 = (4500-error_F1)/4500;
% Step 3: Standard Normal (Z-Score): Assume F1 to be a subjective measure.
% In this case the mean value and the range of data reported by one subject
% will not be consistent with another subject. In other to remove the effect
% of individual differences, you have to normalize the data of each subject
% using the standard normal formulation (removing the mean and dividing by
% standard deviation). Calculate F1 (the standard normal of F1) and plot the
% distribution of the data using F1 and F2, and compare it to the
% distribution in F1 and F2 shown on right.
for i = 1:1000
Z1(i,:) = zscore(F1(i,:));
end
% Plot Z-scores
hold on
for i = 1:5
scatter(Z1(:,i),F2(:,i))
end
title('Scatterplot: Normalized Features')
xlabel('1^{st} Feature (Z1)')
ylabel('2^{nd} Feature (F2)')
legend('C1','C2','C3','C4','C5')
hold off
% Step 3
%Case 2: X = Z1
Z1_train = Z1(1:100,:);
Z1_test = Z1(101:1000,:);
mean_vals_Z1(1,:) = mean(Z1_train,1);
var_vals_Z1(1,:) = var(Z1_train,1);
[z_Z1,p_Z1,I_Z1] = classifier1(Z1_test,mean_vals_Z1(1,:),var_vals_Z1(1,:));
error_mat_Z1 = actual - I_Z1;
idx_Z1=error_mat_Z1==0;
error_Z1=sum(idx_Z1(:));
Correction_Rate_Z1 = error_Z1/4500;
Error_Rate_Z1 = (4500-error_Z1)/4500;
%Case 3: X = F2
[z_F2,p_F2,I_F2] = classifier1(f2_test,mean_vals(2,:),var_vals(2,:));
error_mat_F2 = actual - I_F2;
idx_F2=error_mat_F2==0;
error_F2=sum(idx_F2(:));
Correction_Rate_F2 = error_F2/4500;
Error_Rate_F2 = (4500-error_F2)/4500;
%Case 4: X =
[P,I] = classifier_2(Z1_test,f2_test,mean_vals_Z1(1,:),var_vals_Z1(1,:),mean_vals(2,:),var_vals(2,:));
error_mat = actual - I;
idx=error_mat==0;
error=sum(idx(:));
Correction_Rate = error/4500;
Error_Rate = (4500-error)/4500;