<commit_before>import numpy as np
from scipy.stats import linregress
from sklearn.cross_validation import cross_val_score, KFold
from sklearn.externals import joblib as pickle

def cross_validate(model, cv_set, cv_target, n = 10, shuffle=True, n_jobs = 1):
    if shuffle:
        cv = KFold(len(cv_target), n_folds=n, shuffle=True)
    else:
        cv = n
    return cross_val_score(model, cv_set, cv_target, cv = cv, n_jobs = n_jobs)

### FIX ### If possible make ensemble scorer lazy, for now it consumes all ligands
class scorer(object):
    def __init__(self, model_instances, descriptor_generator_instances, score_title = 'score'):
        """Scorer class is parent class for scoring functions. It's capable of using multiple models and/or multiple descriptors.
        If multiple models and multiple descriptors are used they should be aligned, since no permutation of such is made.
        
        Parameters
        ----------
        model_instances: array of models
            An array of medels compatible with sklearn API (fit, predict and score methods)
        
        descriptor_generator_instances: array of descriptors
            An array of descriptor objects
        
        score_title: string
            Title of score to be used.
        """
        self.model = model_instances
        if type(model_instances) is list:
            self.single_model = False
        else:
            self.single_model = True
        
        self.descriptor_generator = descriptor_generator_instances
        if type(descriptor_generator_instances) is list:
            if len(descriptor_generator_instances) == len(model_instances):
                raise ValueError, "Length of models list doesn't equal descriptors list"
            self.single_descriptor = False
        else:
            self.single_descriptor = True
        self.score_title = score_title
        
    def fit(self, ligands, target, *args, **kwargs):
        """Trains model on supplied ligands and target values
        
        Parameters
        ----------
            ligands: array-like of ligands
                Ground truth (correct) target values.
            
            target: array-like of shape = [n_samples] or [n_samples, n_outputs]
                Estimated target values.
        """
        if self.single_descriptor:<commit_msg>Add docs and train_test_split function<commit_after>import numpy as np
from scipy.stats import linregress
from sklearn.cross_validation import cross_val_score, KFold, train_test_split
from sklearn.externals import joblib as pickle

def cross_validate(model, cv_set, cv_target, n = 10, shuffle=True, n_jobs = 1):
    """Perform cross validation of model using provided data
    
    Parameters
    ----------
        model: object
            Model to be tested
        
        cv_set: array-like of shape = [n_samples, n_features]
            Estimated target values.
        
        cv_target: array-like of shape = [n_samples] or [n_samples, n_outputs]
            Estimated target values.
        
        n: integer (default = 10)
            How many folds to be created from dataset
        
        shuffle: bool (default = True)
            Should data be shuffled before folding.
        
        n_jobs: integer (default = 1)
            How many CPUs to use during cross validation
        
    Returns
    -------
        r2: array of shape = [n]
            R^2 score for each of generated folds
    """
    if shuffle:
        cv = KFold(len(cv_target), n_folds=n, shuffle=True)
    else:
        cv = n
    return cross_val_score(model, cv_set, cv_target, cv = cv, n_jobs = n_jobs)

### FIX ### If possible make ensemble scorer lazy, for now it consumes all ligands
class scorer(object):
    def __init__(self, model_instances, descriptor_generator_instances, score_title = 'score'):
        """Scorer class is parent class for scoring functions. It's capable of using multiple models and/or multiple descriptors.
        If multiple models and multiple descriptors are used they should be aligned, since no permutation of such is made.
        
        Parameters
        ----------
            model_instances: array of models
                An array of medels compatible with sklearn API (fit, predict and score methods)
            
            descriptor_generator_instances: array of descriptors
                An array of descriptor objects
            
            score_title: string
                Title of score to be used.
        """
        self.model = model_instances
        if type(model_instances) is list:
            self.single_model = False
        else:
            self.single_model = True
        
        self.descriptor_generator = descriptor_generator_instances
        if type(descriptor_generator_instances) is list:
            if len(descriptor_generator_instances) == len(model_instances):
                raise ValueError, "Length of models list doesn't equal descriptors list"
            self.single_descriptor = False
        else:
            self.single_descriptor = True
        self.score_title = score_title
        
    def fit(self, ligands, target, *args, **kwargs):
        """Trains model on supplied ligands and target values
        
        Parameters
        ----------
            ligands: array-like of ligands
                Ground truth (correct) target values.
            
            target: array-like of shape = [n_samples] or [n_samples, n_outputs]
                Estimated target values.
        """
        if self.single_descriptor:
{'fraction_non_alphanumeric': 0.06857451403887689, 'fraction_numerical': 0.0019798416126709864, 'mean_word_length': 2.1149103139013454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4789705', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1397, 'n_words': 508}