sample/sample.py
def crossval_predict_files_folds(clf, X_list, y_list, do_subsampling=True, metric=None):
    """
    Perform cross validation on lists of data and targets.
    Use the files / list entries as folds.
    :param clf: classifier object
    :param X_list: list of data arrays
    :param y_list: list of target arrays
    :param do_subsampling: perform subsampling on selection (not on eval data)
    :return:
    """
    y_pred = []
    scores_class0 = []
    scores_class1 = []
    for idx, X_eval in hlp.reverse_enum(X_list):
        # Create selection
        X_sel = X_list[:idx] + X_list[idx + 1:]
        y_sel = y_list[:idx] + y_list[idx + 1:]
        # Concatenate
        X_sel_comb = np.concatenate(X_sel)
        y_sel_comb = np.concatenate(y_sel)
        if do_subsampling:  # Perform subsampling
            X_sel_comb = list(X_sel_comb)
            y_sel_comb = list(y_sel_comb)
            pre.balance_class_sizes(X_sel_comb, y_sel_comb)
        # Learn
        with LogCont("Learn classifier on selection"):
            clf.fit(X_sel_comb, y_sel_comb)
        # Predict
        y_pred_eval = get_prediction(X_eval, clf)
        y_pred += list(y_pred_eval)
        # Evaluate prediction
        scores_both_classes = calc_scores_on_both_classes(y_list[idx], y_pred_eval, 1, metric=metric)
        scores_class0.append(scores_both_classes[0])
        scores_class1.append(scores_both_classes[1])
    scores = [scores_class0, scores_class1]
    return y_pred, scores

    Perform cross validation on lists of data and targets.
    Use the files / list entries as folds.
    :param clf: classifier object
    :param X_list: list of data arrays
    :param y_list: list of target arrays
    :param do_subsampling: perform subsampling on selection (not on eval data)
    :return:
    
Perform cross validation on lists of data and targets.
Use the files / list entries as folds.
Perform cross validation on lists of data and targets . Use the files / list entries as folds .
def crossval_predict_files_folds(clf, X_list, y_list, do_subsampling=True, metric=None):
    y_pred = []
    scores_class0 = []
    scores_class1 = []
    for idx, X_eval in hlp.reverse_enum(X_list):
        X_sel = X_list[:idx] + X_list[idx + 1:]
        y_sel = y_list[:idx] + y_list[idx + 1:]
        X_sel_comb = np.concatenate(X_sel)
        y_sel_comb = np.concatenate(y_sel)
        if do_subsampling:  
            X_sel_comb = list(X_sel_comb)
            y_sel_comb = list(y_sel_comb)
            pre.balance_class_sizes(X_sel_comb, y_sel_comb)
        with LogCont("Learn classifier on selection"):
            clf.fit(X_sel_comb, y_sel_comb)
        y_pred_eval = get_prediction(X_eval, clf)
        y_pred += list(y_pred_eval)
        scores_both_classes = calc_scores_on_both_classes(y_list[idx], y_pred_eval, 1, metric=metric)
        scores_class0.append(scores_both_classes[0])
        scores_class1.append(scores_both_classes[1])
    scores = [scores_class0, scores_class1]
    return y_pred, scores
def crossval_predict_files_folds ( clf , X_list , y_list , do_subsampling = True , metric = None ) : y_pred = [ ] scores_class0 = [ ] scores_class1 = [ ] for idx , X_eval in hlp . reverse_enum ( X_list ) : X_sel = X_list [ : idx ] + X_list [ idx + 1 : ] y_sel = y_list [ : idx ] + y_list [ idx + 1 : ] X_sel_comb = np . concatenate ( X_sel ) y_sel_comb = np . concatenate ( y_sel ) if do_subsampling : X_sel_comb = list ( X_sel_comb ) y_sel_comb = list ( y_sel_comb ) pre . balance_class_sizes ( X_sel_comb , y_sel_comb ) with LogCont ( "Learn classifier on selection" ) : clf . fit ( X_sel_comb , y_sel_comb ) y_pred_eval = get_prediction ( X_eval , clf ) y_pred += list ( y_pred_eval ) scores_both_classes = calc_scores_on_both_classes ( y_list [ idx ] , y_pred_eval , 1 , metric = metric ) scores_class0 . append ( scores_both_classes [ 0 ] ) scores_class1 . append ( scores_both_classes [ 1 ] ) scores = [ scores_class0 , scores_class1 ] return y_pred , scores
Perform cross validation on lists of data and targets.
Perform cross validation on lists of data and targets .
"""
    Perform cross validation on lists of data and targets.
    Use the files / list entries as folds.
    :param clf: classifier object
    :param X_list: list of data arrays
    :param y_list: list of target arrays
    :param do_subsampling: perform subsampling on selection (not on eval data)
    :return:
    """ # Create selection # Concatenate # Perform subsampling # Learn # Predict # Evaluate prediction
None
clf
None
X_list
list of data arrays
list of data arrays
y_list
list of target arrays
list of target arrays
do_subsampling
perform subsampling on selection (not on eval data)
perform subsampling on selection ( not on eval data )
metric