Returns train and test indexes for k-fold cross-validation.
Parameters : |
|
---|---|
Returns : |
|
Example:
>>> import mlpy
>>> idx = mlpy.cv_kfold(n=12, k=3)
>>> for tr, ts in idx: tr, ts
...
(array([2, 8, 1, 7, 9, 3, 0, 5]), array([ 6, 11, 4, 10]))
(array([ 6, 11, 4, 10, 9, 3, 0, 5]), array([2, 8, 1, 7]))
(array([ 6, 11, 4, 10, 2, 8, 1, 7]), array([9, 3, 0, 5]))
>>> strat = [0,0,0,0,0,0,0,0,1,1,1,1]
>>> idx = mlpy.cv_kfold(12, k=4, strat=strat)
>>> for tr, ts in idx: tr, ts
...
(array([ 1, 7, 3, 0, 5, 4, 8, 10, 9]), array([ 6, 2, 11]))
(array([ 6, 2, 3, 0, 5, 4, 11, 10, 9]), array([1, 7, 8]))
(array([ 6, 2, 1, 7, 5, 4, 11, 8, 9]), array([ 3, 0, 10]))
(array([ 6, 2, 1, 7, 3, 0, 11, 8, 10]), array([5, 4, 9]))
Returns train and test indexes for random subsampling cross-validation. The proportion of the train/test indexes is not dependent on the number of iterations k.
Parameters : |
|
---|---|
Returns : |
|
Example:
>>> import mlpy
>>> ap = mlpy.cv_random(n=12, k=4, p=30)
>>> for tr, ts in ap: tr, ts
...
(array([ 6, 11, 4, 10, 2, 8, 1, 7, 9]), array([3, 0, 5]))
(array([ 5, 2, 3, 4, 9, 0, 11, 7, 6]), array([ 1, 10, 8]))
(array([ 6, 1, 10, 2, 7, 5, 11, 0, 3]), array([4, 9, 8]))
(array([2, 4, 8, 9, 5, 6, 1, 0, 7]), array([10, 11, 3]))
Returns train and test indexes for all-combinations cross-validation.
Parameters : |
|
---|---|
Returns : |
|
Example
>>> import mlpy
>>> idx = mlpy.cv_all(n=4, p=50)
>>> for tr, ts in idx: tr, ts
...
(array([2, 3]), array([0, 1]))
(array([1, 3]), array([0, 2]))
(array([1, 2]), array([0, 3]))
(array([0, 3]), array([1, 2]))
(array([0, 2]), array([1, 3]))
(array([0, 1]), array([2, 3]))
>>> idx = mlpy.cv_all(a, 10) # ValueError: p must be >= 25.000