'awareness',
                      'confidence',
                      ]
 target_name     = 'awareness'
 experiment      = 'e1'
 # for some of the variables, we need to rescale them to a more preferable range like 0-1
 name_for_scale  = ['awareness']
 # ['ah', 'av', 'bj', 'cm', 'db', 'ddb', 'fcm', 'kf', 'kk', 'ml', 'qa','sk', 'yv']
 # get one of the participants' data
 participant = 'db'
 df_sub          = df[df['participant'] == participant]
 # for 1-back to 4-back
 for n_back in np.arange(1,5):
     X,y,groups = utils.get_features_targets_groups(
                             df_sub.dropna(),
                             n_back                  = n_back,
                             names                   = name_for_scale,
                             independent_variables   = feature_names,
                             dependent_variable      = [target_name,'correctness'])
     X,y,groups = shuffle(X,y,groups)
     y,correctness = y[:,0],y[:,1]
     for model_name,model in utils.make_clfs().items():
         cv = LeaveOneOut()
         print('{}-back,{}'.format(n_back,model_name))
         preds = cross_val_predict(model,X,y,groups=groups,cv=cv,method='predict',verbose=2,n_jobs=4)
         df_pred_ = pd.DataFrame(np.vstack([preds,correctness]).T,columns = ['preds','correct'])
         p_correct = float(np.sum(correctness == 1)+1) / (len(correctness)+1)
         p_incorrect = float(np.sum(correctness == 0)+1) / (len(correctness)+1)
         p_aware = float(np.sum(preds == 1)+1) / (len(preds)+1)
         p_unaware = float(np.sum(preds == 0)+1) / (len(preds)+1)
         p_correct_aware = float(np.sum(np.logical_and(correctness == 1, preds == 1))+1) / (len(df_pred_)+1)
         p_correct_unaware = float(np.sum(np.logical_and(correctness == 1, preds == 0))+1) / (len(df_pred_)+1)
コード例 #2
0
results_full = dict(
        model       = [],
        train       = [],
        test        = [],
        score       = [],
        fold        = [],
        window      = []
        )
for n_back in range(5): # loop through the number of N-back trials
    # get the features, targets, and subject groups for both experiments and the given n_back trial
    X_att,y_att,groups_att              = get_features_targets_groups(
            att,# the loaded dataframe
            n_back                      = n_back, # n_back trials
            names                       = ['attention',# need to normalize to 0 and 1
                                           'awareness',# need to normalize to 0 and 1
                                           'confidence'],# need to normalize to 0 and 1
            independent_variables       = ['correct',
                                           'awareness',
                                           'confidence'],
            dependent_variable          =  'attention'
            )
    X_pos,y_pos,groups_pos              = get_features_targets_groups(
            pos,
            n_back                      = n_back,
            names                       = ['success',# need to normalize to 0 and 1
                                           'awareness',# need to normalize to 0 and 1
                                           'confidence'],# need to normalize to 0 and 1
            independent_variables       = ['correct',
                                           'awareness',
                                           'confidence'],
            dependent_variable          =  'success'