Skip to content

Instantly share code, notes, and snippets.

@milkersarac
Created September 3, 2013 09:33
Show Gist options
  • Save milkersarac/6421653 to your computer and use it in GitHub Desktop.
Save milkersarac/6421653 to your computer and use it in GitHub Desktop.
Converts feature matrix to weka's .arff format. I used https://github.com/decabyte/arff_matlab for core functionality.
% write_mat_to_arff.m
% Authors:milkers
clear all; close all; clc;
path(path, '..');
%%
features = dir('/home/ilker/Desktop/matToArff/arff_matlab/model_features/');
filenames = dir('/home/ilker/Desktop/matToArff/arff_matlab/model_features_files/');
filename_base = '/home/ilker/Desktop/matToArff/arff_matlab/model_features_files/';
feat_base = '/home/ilker/Desktop/matToArff/arff_matlab/model_features/';
for i=3:length(features)
% for i=3:3
display([int2str(i-2) '-' features(i).name ' started.'])
load([filename_base features(i).name]);%returns a cell named cur_filenames
load([feat_base features(i).name]);%returns a matrix named cur_mat
[pathstr, concept_name, ext] = fileparts(features(i).name);
%create data structure
data = struct();
relname = sprintf([concept_name '_weka']);
outfile = sprintf('/home/ilker/Desktop/matToArff/arff_matlab/weka_data/%s.arff', relname);
type_class = {'positive', 'negative'};
%modify dataset
for j=1:length(cur_filenames)%number of positive images*3
[pathstr, tmp_name, ext] = fileparts(cur_filenames{j,1});
[pathstr, image_name, ext] = fileparts(tmp_name);
data(j).idx = [concept_name '_' image_name];
feat_size = size(cur_mat);
for k=1:feat_size(2)-1%4648-1=4647
data(j).(['f' int2str(k)]) = cur_mat(j,k);
%display(cur_mat(j,k));
end
if cur_mat(j,4648) > 0
data(j).type_class = 'positive';
else
data(j).type_class = 'negative';
end
display([int2str(j) '-' features(i).name ' dataset modified.'])
end
nomspec.type_class = type_class;
arff_write(outfile, data, relname, nomspec);
display([int2str(i-2) '-' concept_name ' is finished.'])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment