Browse Source

Added conversion of nominal attributes to integer

Ioannis Agtzidis 5 years ago
parent
commit
0eec436468
1 changed files with 24 additions and 0 deletions
  1. 24 0
      Nom2IntArff.m

+ 24 - 0
Nom2IntArff.m

@@ -0,0 +1,24 @@
+% Nom2IntArff.m
+%
+% This function converts all the nominal attributes in the provided ARFF file
+% to integer attributes. This helps speeding-up loading and saving times for
+% very large ARFF files.
+%
+% input:
+%   inputfile   - ARFF file to convert
+%   outputfile  - file to store changed ARFF
+
+function Nom2IntArff(inputfile, outputfile)
+    [data, metadata, attributes, relation, comments] = LoadArff(inputfile);
+
+    for i=1:size(attributes,1)
+        isNom = IsNomAttribute(attributes{i,2});
+        if (isNom)
+            description = [' Attribute ' attributes{i,1} ' ' attributes{i,2} ' was converted to integer'];
+            comments{end+1} = description;
+            attributes{i,2} = 'integer';
+        end
+    end
+
+    SaveArff(outputfile, data, metadata, attributes, relation, comments);
+end