Skip to content

Commit

Permalink
Added pima-getter
Browse files Browse the repository at this point in the history
  • Loading branch information
wmkouw committed May 14, 2017
1 parent e95fbb4 commit 0529c34
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
22 changes: 22 additions & 0 deletions data/pima/get_pima.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function [D,y] = get_pima(varargin)
% Script to download pima diabetes dataset from UCI machine learning repository

% Parse
p = inputParser;
addOptional(p, 'save', false);
parse(p, varargin{:});

%% Start downloading files

fprintf('Starting downloads..')
websave('pima-indians-diabetes.data', ...
'https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data');
websave('pima-indians-diabetes.names', ...
'https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.names');

fprintf('Done \n')

%% Call parse script
[D,y] = parse_pima_gen('save', p.Results.save);

end
53 changes: 53 additions & 0 deletions data/pima/parse_pima_gen.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function [D,y] = parse_pima_gen(varargin)
%% Import data from text file.
% Script for importing data from the following text file:
%
% ./pima-indians-diabetes.data
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.

% Auto-generated by MATLAB on 2017/05/13 23:19:09

% Parse
p = inputParser;
addOptional(p, 'save', false);
parse(p, varargin{:});

%% Initialize variables.
filename = './pima-indians-diabetes.data';
delimiter = ',';

%% Format for each line of text:

% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%f%f%f%f%f%f%f%f%[^\n\r]';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to the format.
% This call is based on the structure of the file used to generate this code. If
% an error occurs for a different file, try regenerating the code from the
% Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false);

%% Close the text file.
fclose(fileID);

%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for unimportable
% data, select unimportable cells in a file and regenerate the script.

%% Allocate imported array to column variable names
D = cell2mat(dataArray(:,1:end-2));
y = cell2mat(dataArray(:,end-1));

y(y==0) = -1;

if p.Results.save
save('pima', 'D','y');
end

end

0 comments on commit 0529c34

Please sign in to comment.