Skip to content

Instantly share code, notes, and snippets.

@vabenjamin
Created February 22, 2013 06:36
Show Gist options
  • Save vabenjamin/5011261 to your computer and use it in GitHub Desktop.
Save vabenjamin/5011261 to your computer and use it in GitHub Desktop.
def test_n_fold_validation
data = []
data << [4,3,1] << [1,1,3] << [5,2,1] << [6,9,7] << [9,8,9] << [7,3,5] << [11,4,2] << [12,1,8] << [3,8,6]
number_of_folds = 4
folds = []
folds << BrilliantRuby::ML.n_fold_validation(number_of_folds, data)
assert(folds.length == 4, "Unexpected number of folds created")
end
----------------------------
def self.n_fold_validation(n_folds, data)
#create bins
p data
..
output:
3
1
1
1
3
5
2
1
6
9
7
9
8
9
7
3
5
11
4
2
12
1
8
3
8
6
4
3
1
1
1
3
5
2
1
6
9
7
9
8
9
7
3
5
11
4
2
12
1
8
3
8
6
4
3
1
1
1
3
5
2
1
6
9
7
9
8
9
7
3
5
11
4
2
12
1
8
3
8
6
4
3
1
1
1
3
5
2
1
6
9
7
9
8
7
3
5
11
4
2
12
1
8
6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment