This repository was archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTesting.m
More file actions
135 lines (126 loc) · 3.08 KB
/
Testing.m
File metadata and controls
135 lines (126 loc) · 3.08 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
% Get list of all of the file names in the positive review folder
% filelist = getAllFiles('.\positive');
% filelist = cellfun(@(x)(x(2:end)), filelist, 'uni', false);
% % Read in the data for all positive reviews
% loadPositiveData
%
% % Read in the data for all negative reviews
% loadNegativeData
%Load training data
load('TrainingData.mat')
sizeTrainingData=size(TrainingData,1)
%Load testing data
load('TestData.mat')
sizeTestData=size(TestData,1)
%load positive vocabulary words
positiveVocabPath=fullfile('Data','TextODS','positive.ods');
positiveVocabulary=readtable(positiveVocabPath);
%load negative vocabulary words
negativeVocabPath=fullfile('Data','TextODS','negative.ods');
negativeVocabulary=readtable(negativeVocabPath);
negativeVocabulary.Properties.VariableNames{'x2_face'} = 'words';
positiveVocabulary.Properties.VariableNames{'a_'} = 'words';
label_train=zeros(sizeTrainingData,1)
label_test=zeros(sizeTestData,1)
error=0
%strcmp(s1,s2) - compares string values
for (i=1:sizeTrainingData)
review=TrainingData{i}
review=cell2table(review)
sizeReview=size(review,1)
review.Properties.VariableNames{'review'} = 'words';
negative=intersect(review,negativeVocabulary)
positive=intersect(review,positiveVocabulary)
if (size(negative,1)>=size(positive,1))
label_train(i)=-1
else label_train(i)=1
end
if(label_train(i)~=TrainingData{i,2})
error=error+1
end
end
fprintf('error %d', error)
errorTest=0
for (j=1:sizeTestData)
review=TestData{j}
review=cell2table(review)
sizeReview=size(review,1)
review.Properties.VariableNames{'review'} = 'words';
negative=intersect(review,negativeVocabulary)
positive=intersect(review,positiveVocabulary)
if (size(negative,1)>=size(positive,1))
label_test(j)=2
else label_test(j)=1
end
if(label_test(j)~=TestData{j,2})
errorTest=errorTest+1
end
end
fprintf('error Test%d', errorTest)
% for i=1:sizeData
% Data{1}(i)
% end
% % do_kernel_perceptron.m
%
% MAX_EPOCH=100;
% ETA=0.00001;
% NORMALIZE=0;
%
% % Kernel parameters
% K_TYPE = 'gaussian';
% K_PARAMS = {5};
%
% % Positive class
% POS=1;
%
% % Load data
% load('email.mat');
%
% Ntrain = size(Ftrain,1);
%
% % Class POS versus the rest.
% % This sets up L as +/-1 for the two classes.
% L = (Ltrain == POS) - (Ltrain~= POS);
%
% if NORMALIZE
% tr_mean = mean(Ftrain,1);
% tr_std = std(Ftrain,1,1) + eps;
% Ftrain = Ftrain - repmat(tr_mean, [Ntrain 1]);
% Ftrain = Ftrain ./ repmat(tr_std, [Ntrain 1]);
% end
%
% % Train kernel perceptron
% % Compute gram matrix
% K = gramMatrix(Ftrain,Ftrain,K_TYPE,K_PARAMS);
%
% % Run stochastic gradient descent
% Alpha = zeros(Ntrain,1);
%
% for epoch=1:MAX_EPOCH
% rp = randperm(Ntrain);
% for n_i=rp
% % TO DO:: Stochastic gradient update.
%
%
%
%
%
%
%
%
%
%
%
%
%
% end
%
% % Debug: print out total error.
% Fn = sign((Alpha') * K)';
% nerr = sum(Fn ~= L);
% fprintf('Epoch %d: error %d\n', epoch, nerr);
%
% if nerr <=0
% break
% end
% end