Skip to content

Commit

Permalink
Corrected error in k fold
Browse files Browse the repository at this point in the history
  • Loading branch information
pagutierrez committed Jan 20, 2018
1 parent 086dc7b commit 933a010
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
52 changes: 51 additions & 1 deletion doc/orca-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,57 @@ ans =
dlmwrite(fullfile(rootDir,sprintf('test-%s.%d',nameDataset,ff-1)),ERAData(teIdx,:),' ');
end
```
This will generate all the partitions for a `10`fold crossvalidation experimental design. The source code of this example is in [exampleERAKFold.m](../src/code-examples/exampleERAKFold.m). In order to obtain a `30`holdout design, the code will be a bit different:
This will generate all the partitions for a `10`fold crossvalidation experimental design. The source code of this example is in [exampleERAKFold.m](../src/code-examples/exampleERAKFold.m).

In order to obtain a `30`holdout design, the code will be a bit different. As MATLAB does not included a native way of repeating holdout, we will do it manually:
```Matlab
>> % Load data
ERAData = table2array(readtable('../../exampledata/ERA.csv'));
>> % Check the first 20 rows
ERAData(1:20,:)
ans =
3 2 0 14 1
3 3 5 9 1
1 3 10 7 1
0 5 7 2 1
0 10 12 7 1
0 5 7 2 1
2 1 5 1 1
0 5 7 2 1
3 2 0 14 1
10 7 1 6 1
1 2 12 4 1
2 1 5 1 1
1 3 10 7 1
0 5 7 2 1
3 2 0 14 1
1 9 4 1 1
2 1 5 1 1
3 2 0 14 1
2 1 5 1 1
5 7 3 12 1
>> % Extract targets
targets = ERAData(:,end);
>> % Generate h holdout partitions
h=30;
>> % Prepare filesystem
nameDataset = 'era';
rootDir = fullfile('..', '..', 'exampledata', '30-holdout', nameDataset);
mkdir(rootDir);
rootDir = fullfile(rootDir,'matlab');
mkdir(rootDir);
>> % For each partitions
for ff = 1:h
CVO = cvpartition(targets,'HoldOut',0.25); % 25% of patterns for the test set
trIdx = CVO.training(1);
teIdx = CVO.test(1);
dlmwrite(fullfile(rootDir,sprintf('train-%s.%d',nameDataset,ff-1)),ERAData(trIdx,:),' ');
dlmwrite(fullfile(rootDir,sprintf('test-%s.%d',nameDataset,ff-1)),ERAData(teIdx,:),' ');
end
```


### Warning about highly imbalanced datasets
Expand Down
2 changes: 1 addition & 1 deletion src/code-examples/exampleERAKFold.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

% Generate k fold partitions
k=10;
CVO = cvpartition(targets,'k',k);
CVO = cvpartition(targets,'KFold',k);

% Prepare filesystem
nameDataset = 'era';
Expand Down

0 comments on commit 933a010

Please sign in to comment.