<commit_before># Author: <NAME> <<EMAIL>>
# License: BSD Style.

# $Id$

import exceptions

import numpy as np

def leave_one_out(n):
    """
    Leave-One-Out cross validation:
    Provides train/test indexes to split data in train test sets

    Parameters
    ===========
    n: int
        Total number of elements

    Examples
    ========
 
    >>> import numpy as np
    >>> import scikits.learn.utils.crossval
    >>> n_samples, n_features = 5, 10
    >>> X = np.random.randn(n_samples, n_features)
    >>> loo = crossval.LOO(n_samples)
    >>> for train_index, test_index in loo:
    ...    print "TRAIN:", train_index, "TEST:", test_index
    ...    Xtrain, Xtest, Ytrain, Ytest = split(train_index, test_index, X, y)
    ...    print Xtrain, Xtest, Ytrain, Ytest
    """
    for i in xrange(n):
        test_index  = np.zeros(n, dtype=np.bool)
        test_index[i] = True
        train_index = np.logical_not(test_index)
        yield train_index, test_index


def k_fold(n, k):
    """
    K-Folds cross validation:
    Provides train/test indexes to split data in train test sets

    Parameters
    ===========
    n: int
        Total number of elements
    k: int
        number of folds

    Note
    ====
    All the folds have size trunc(n/k), the last one has the complementary<commit_msg>Fix some docstring failures in crossval<commit_after># Author: <NAME> <<EMAIL>>
# License: BSD Style.

# $Id$

import exceptions

import numpy as np

def leave_one_out(n):
    """
    Leave-One-Out cross validation:
    Provides train/test indexes to split data in train test sets

    Parameters
    ===========
    n: int
        Total number of elements

    Examples
    ========
 
    >>> import numpy as np
    >>> from scikits.learn.utils import crossval
    >>> n_samples, n_features = 5, 10
    >>> X = np.random.randn(n_samples, n_features)
    >>> loo = crossval.leave_one_out(n_samples)
    >>> for train_index, test_index in loo:
    ...    print "TRAIN:", train_index, "TEST:", test_index
    ...    Xtrain, Xtest, Ytrain, Ytest = split(train_index, test_index, X, y)
    ...    print Xtrain, Xtest, Ytrain, Ytest
    """
    for i in xrange(n):
        test_index  = np.zeros(n, dtype=np.bool)
        test_index[i] = True
        train_index = np.logical_not(test_index)
        yield train_index, test_index


def k_fold(n, k):
    """
    K-Folds cross validation:
    Provides train/test indexes to split data in train test sets

    Parameters
    ===========
    n: int
        Total number of elements
    k: int
        number of folds

    Note
    ====
    All the folds have size trunc(n/k), the last one has the complementary
{'fraction_non_alphanumeric': 0.12354487420202778, 'fraction_numerical': 0.0022530980097634247, 'mean_word_length': 2.537848605577689, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246173', 'n_tokens_mistral': 883, 'n_tokens_neox': 838, 'n_words': 266}