-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |