|
a |
|
b/classification/SMOTEBoost/Test.m |
|
|
1 |
clc; |
|
|
2 |
clear all; |
|
|
3 |
close all; |
|
|
4 |
|
|
|
5 |
file = 'data.csv'; % Dataset |
|
|
6 |
|
|
|
7 |
% Reading training file |
|
|
8 |
data = dlmread(file); |
|
|
9 |
label = data(:,end); |
|
|
10 |
|
|
|
11 |
% Extracting positive data points |
|
|
12 |
idx = (label==1); |
|
|
13 |
pos_data = data(idx,:); |
|
|
14 |
row_pos = size(pos_data,1); |
|
|
15 |
|
|
|
16 |
% Extracting negative data points |
|
|
17 |
neg_data = data(~idx,:); |
|
|
18 |
row_neg = size(neg_data,1); |
|
|
19 |
|
|
|
20 |
% Random permuation of positive and negative data points |
|
|
21 |
p = randperm(row_pos); |
|
|
22 |
n = randperm(row_neg); |
|
|
23 |
|
|
|
24 |
% 80-20 split for training and test |
|
|
25 |
tstpf = p(1:round(row_pos/5)); |
|
|
26 |
tstnf = n(1:round(row_neg/5)); |
|
|
27 |
trpf = setdiff(p, tstpf); |
|
|
28 |
trnf = setdiff(n, tstnf); |
|
|
29 |
|
|
|
30 |
train_data = [pos_data(trpf,:);neg_data(trnf,:)]; |
|
|
31 |
test_data = [pos_data(tstpf,:);neg_data(tstnf,:)]; |
|
|
32 |
|
|
|
33 |
% Decision Tree |
|
|
34 |
prediction = SMOTEBoost(train_data,test_data,'tree',false); |
|
|
35 |
disp (' Label Probability'); |
|
|
36 |
disp ('-----------------------------'); |
|
|
37 |
disp (prediction); |