6.10.2.2.2. statsmodels.sandbox.tools.cross_val.KStepAhead

class statsmodels.sandbox.tools.cross_val.KStepAhead(n, k=1, start=None, kall=True, return_slice=True)[source]

KStepAhead cross validation iterator: Provides fit/test indexes to split data in sequential sets

KStepAhead cross validation iterator: Provides train/test indexes to split data in train test sets

Parameters:

n: int

Total number of elements

k : int

number of steps ahead

start : int

initial size of data for fitting

kall : boolean

if true. all values for up to k-step ahead are included in the test index. If false, then only the k-th step ahead value is returnd

Notes

I don’t think this is really useful, because it can be done with a very simple loop instead. Useful as a plugin, but it could return slices instead for faster array access.

Examples

>>> from scikits.learn import cross_val
>>> X = [[1, 2], [3, 4]]
>>> y = [1, 2]
>>> loo = cross_val.LeaveOneOut(2)
>>> for train_index, test_index in loo:
...    print "TRAIN:", train_index, "TEST:", test_index
...    X_train, X_test, y_train, y_test = cross_val.split(train_index, test_index, X, y)
...    print X_train, X_test, y_train, y_test
TRAIN: [False  True] TEST: [ True False]
[[3 4]] [[1 2]] [2] [1]
TRAIN: [ True False] TEST: [False  True]
[[1 2]] [[3 4]] [1] [2]
__init__(n, k=1, start=None, kall=True, return_slice=True)[source]

KStepAhead cross validation iterator: Provides train/test indexes to split data in train test sets

Parameters:

n: int

Total number of elements

k : int

number of steps ahead

start : int

initial size of data for fitting

kall : boolean

if true. all values for up to k-step ahead are included in the test index. If false, then only the k-th step ahead value is returnd

Notes

I don’t think this is really useful, because it can be done with a very simple loop instead. Useful as a plugin, but it could return slices instead for faster array access.

Examples

>>> from scikits.learn import cross_val
>>> X = [[1, 2], [3, 4]]
>>> y = [1, 2]
>>> loo = cross_val.LeaveOneOut(2)
>>> for train_index, test_index in loo:
...    print "TRAIN:", train_index, "TEST:", test_index
...    X_train, X_test, y_train, y_test = cross_val.split(train_index, test_index, X, y)
...    print X_train, X_test, y_train, y_test
TRAIN: [False  True] TEST: [ True False]
[[3 4]] [[1 2]] [2] [1]
TRAIN: [ True False] TEST: [False  True]
[[1 2]] [[3 4]] [1] [2]

6.10.2.2.2.1. Methods

__init__(n[, k, start, kall, return_slice]) KStepAhead cross validation iterator: