Ejemplo n.º 1
0
    df_high_awe = df_sub[df_sub['awareness'] == 'Aware'].sort_values(['sub','variable','Rating',])
    df_low_awe = df_sub[df_sub['awareness'] == 'Unaware'].sort_values(['sub','variable','Rating',])
    ps = utils.resample_ttest_2sample(df_high_awe['value'].values,
                                      df_low_awe['value'].values,
                                      n_ps = 100,
                                      n_permutation = 5000)
    results['dprime_type'].append(dpr)
    results['experiment'].append(exp)
    results['ps_mean'].append(ps.mean())
    results['ps_std'].append(ps.std())
    results['high_aware'].append(df_high_awe['value'].values.mean())
    results['low_aware'].append(df_low_awe['value'].values.mean())
results = pd.DataFrame(results)

results = results.sort_values('ps_mean')
converter = utils.MCPConverter(pvals = results['ps_mean'].values)
d = converter.adjust_many()
results['p_corrected'] = d['bonferroni'].values

results['stars'] = results['p_corrected'].apply(utils.stars)


for experiment in pd.unique(df_plot['Experiment']):
    results_sub = results[results['experiment'] == experiment]
    g = sns.catplot(x = 'awareness',
                       y = 'value',
                       hue = 'Rating',
                       col = 'dprime_type',
#                       row = 'Experiment',
                       data = df_plot[df_plot['Experiment'] == experiment],
                       aspect = 2,
    df_sub
    anova = ols('mean_variance ~ model_name',data = df_sub).fit()
    aov_table = sm.stats.anova_lm(anova,typ=2)
    print(aov_table)
    temp['F'].append(aov_table['F']['model_name'])
    temp['df_nonimator'].append(aov_table['df']['model_name'])
    temp['df_denominator'].append(aov_table['df']['Residual'])
    temp['p'].append(aov_table['PR(>F)']['model_name'])
    temp['model'].append(model)
    temp['condition'].append(condition)
    temp['roi'].append(roi)
anova_results = pd.DataFrame(temp)
temp = []
for roi,df_sub in anova_results.groupby('condition'):
    df_sub = df_sub.sort_values('p')
    converter = utils.MCPConverter(pvals = df_sub['p'].values)
    d = converter.adjust_many()
    df_sub['p_corrected'] = d['bonferroni'].values
    temp.append(df_sub)
anova_results = pd.concat(temp)
anova_results['stars'] = anova_results['p_corrected'].apply(utils.stars)
anova_results = anova_results.sort_values(['roi','condition','model'])


g = sns.catplot(x = 'roi',
                y = 'mean_variance',
                hue = 'model_name',
                hue_order = ['vgg19', 
                             'densenet121', 
                             'mobilenetv2_1', 
                             'Fast_Text', 
Ejemplo n.º 3
0
                              0.5,
                              n_ps=100,
                              n_permutation=int(1e4),
                              one_tail=True)
    df_post['model'].append(model_name)
    df_post['window'].append(window)
    df_post['train'].append(train)
    df_post['score_mean'].append(df_sub['score'].values.mean())
    df_post['score_std'].append(df_sub['score'].values.std())
    df_post['pval'].append(ps.mean())
df_post = pd.DataFrame(df_post)
temp = []
for (train, model_name), df_sub in df_post.groupby(['train', 'model']):
    df_sub = df_sub.sort_values(['pval'])
    ps = df_sub['pval'].values
    converter = utils.MCPConverter(pvals=ps)
    d = converter.adjust_many()
    df_sub['p_corrected'] = d['bonferroni'].values
    temp.append(df_sub)
df_post = pd.concat(temp)

df_post['star'] = df_post['p_corrected'].apply(utils.stars)
df_post = df_post.sort_values(['window', 'train', 'model'])
df_post = df_post[df_post['window'] > 0]

df_plot['experiment_train'] = df_plot['experiment_train'].map({
    'POS':
    "Trained on Exp.1/ Tested on Exp.2",
    'ATT':
    "Trained on Exp.2/ Tested on Exp.1"
})
                                        one_tail=True)
    ps42 = utils.resample_ttest_2sample(m4['value'].values,
                                        m2['value'].values,
                                        n_ps=200,
                                        n_permutation=5000)
    for var_name, name in zip(['model', 'experiment', 'window'], attri):
        results[var_name].append(name)
    results['ps21'].append(ps21.mean())
    results['ps32'].append(ps32.mean())
    results['ps42'].append(ps42.mean())
results = pd.DataFrame(results)

corrected = []
for attri, df_sub in results.groupby(['model', 'experiment']):
    df_sub = df_sub.iloc[np.argsort(df_sub['ps21'].values), :]
    converter = utils.MCPConverter(pvals=df_sub['ps21'].values)
    d = converter.adjust('bonferroni')
    df_sub['ps21_corrected'] = d

    df_sub = df_sub.iloc[np.argsort(df_sub['ps32'].values), :]
    converter = utils.MCPConverter(pvals=df_sub['ps32'].values)
    d = converter.adjust('bonferroni')
    df_sub['ps32_corrected'] = d

    df_sub = df_sub.iloc[np.argsort(df_sub['ps42'].values), :]
    converter = utils.MCPConverter(pvals=df_sub['ps42'].values)
    d = converter.adjust('bonferroni')
    df_sub['ps42_corrected'] = d

    corrected.append(df_sub)
corrected = pd.concat(corrected)