[b4b313]: / classification / SMOTEBoost / CSVtoARFF.m

Download this file

39 lines (32 with data), 914 Bytes

 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
function r = CSVtoARFF (data, relation, type)
% csv to arff file converter
% load the csv data
[rows cols] = size(data);
% open the arff file for writing
farff = fopen(strcat(type,'.arff'), 'w');
% print the relation part of the header
fprintf(farff, '@relation %s', relation);
% Reading from the ARFF header
fid = fopen('ARFFheader.txt','r');
tline = fgets(fid);
while ischar(tline)
tline = fgets(fid);
fprintf(farff,'%s',tline);
end
fclose(fid);
% Converting the data
for i = 1 : rows
% print the attribute values for the data point
for j = 1 : cols - 1
if data(i,j) ~= -1 % check if it is a missing value
fprintf(farff, '%d,', data(i,j));
else
fprintf(farff, '?,');
end
end
% print the label for the data point
fprintf(farff, '%d\n', data(i,end));
end
% close the file
fclose(farff);
r = 0;