Skip to content

Instantly share code, notes, and snippets.

@garydoranjr
Created October 11, 2012 13:02
Show Gist options
  • Save garydoranjr/3872119 to your computer and use it in GitHub Desktop.
Save garydoranjr/3872119 to your computer and use it in GitHub Desktop.
MATLAB function to load datasets
function [examples classifications] = dataset_load(dataset_name)
% dataset_load(dataset_name)
% Returns the example feature vectors (as rows) and corresponding
% classifications. Automatically strips the first column (example ids).
% Load dataset into a structure array
mat_struct = load(dataset_name);
% Syntax to get the field of a structure array by name
% http://www.mathworks.com/help/matlab/ref/getfield.html
X = mat_struct.(dataset_name);
% Skip the first feature (example id)
examples = X(:, 2:end-1);
% Adjust {0, 1} labels to {-1, 1} labels
classifications = 2*X(:, end) - 1;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment