<commit_before>"""
Test the searchlight module
"""
# Author: <NAME>
# License: simplified BSD

from nose.tools import assert_equal
import numpy as np
import nibabel
from .. import searchlight


def test_searchlight():
    # Create a toy dataset to run searchlight on

    # Initialize with 4x4x4 scans of random values on 30 frames
    rand = np.random.RandomState(0)
    frames = 30
    data = rand.rand(5, 5, 5, frames)
    mask = np.ones((5, 5, 5), np.bool)
    mask_img = nibabel.Nifti1Image(mask.astype(np.int), np.eye(4))
    # Create a condition array
    cond = np.asarray([int(i > (frames / 2)) for i in range(frames)])

    # Create an activation pixel.
    data[2, 2, 2, :] = 0
    data[2, 2, 2][cond.astype(np.bool)] = 2
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    # Define score function
    from sklearn.metrics import accuracy_score
    score_func = accuracy_score

    # Define cross validation
    from sklearn.cross_validation import KFold
    cv = KFold(cond.size, k=4)<commit_msg>Backward compatibility: Support older skl version for accuracy score<commit_after>"""
Test the searchlight module
"""
# Author: <NAME>
# License: simplified BSD

from nose.tools import assert_equal
import numpy as np
import nibabel
from .. import searchlight


def test_searchlight():
    # Create a toy dataset to run searchlight on

    # Initialize with 4x4x4 scans of random values on 30 frames
    rand = np.random.RandomState(0)
    frames = 30
    data = rand.rand(5, 5, 5, frames)
    mask = np.ones((5, 5, 5), np.bool)
    mask_img = nibabel.Nifti1Image(mask.astype(np.int), np.eye(4))
    # Create a condition array
    cond = np.asarray([int(i > (frames / 2)) for i in range(frames)])

    # Create an activation pixel.
    data[2, 2, 2, :] = 0
    data[2, 2, 2][cond.astype(np.bool)] = 2
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    # Define score function
    try:
        from sklearn.metrics import accuracy_score
        score_func = accuracy_score
    except:
        from sklearn.metrics import prediction_score
        score_func = prediction_score

    # Define cross validation
    from sklearn.cross_validation import KFold
    cv = KFold(cond.size, k=4)
{'fraction_non_alphanumeric': 0.1040436165379373, 'fraction_numerical': 0.025442980463425715, 'mean_word_length': 3.2427745664739884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5703062', 'n_tokens_mistral': 764, 'n_tokens_neox': 706, 'n_words': 227}