https://github.com/int-brain-lab/paper-behavior
Raw File
Tip revision: edc453189104a1f76f4b2ab230cd86f2140e3f63 authored by Anne Urai on 08 April 2021, 13:13:40 UTC
added revision after peer review to contribution table
Tip revision: edc4531
suppfig_plot_classifier_first_biased.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Plot the results from the classification of lab by loading in the .pkl files generated by
figure3f_decoding_lab_membership_basic and figure3f_decoding_lab_membership_full

Guido Meijer
18 Jun 2020
"""

import pandas as pd
import numpy as np
import seaborn as sns
from os.path import join
import matplotlib.pyplot as plt
from paper_behavior_functions import seaborn_style, figpath, load_csv, FIGURE_WIDTH, FIGURE_HEIGHT

# Settings
FIG_PATH = figpath()
colors = [[1, 1, 1], [1, 1, 1], [0.6, 0.6, 0.6]]
seaborn_style()

# Load in results from csv file
decoding_result = load_csv('classification_results', 'classification_results_full_bayes.pkl')

# Calculate if decoder performs above chance
chance_level = decoding_result['original_shuffled'].mean()
significance = np.percentile(decoding_result['original'], 2.5)
sig_control = np.percentile(decoding_result['control'], 0.001)
if chance_level > significance:
    print('Classification performance not significanlty above chance')
else:
    print('Above chance classification performance!')

    # %%

f, ax1 = plt.subplots(1, 1, figsize=(FIGURE_WIDTH/5, FIGURE_HEIGHT))
sns.violinplot(data=pd.concat([decoding_result['control'],
                               decoding_result['original_shuffled'],
                               decoding_result['original']], axis=1),
               palette=colors, ax=ax1)
ax1.plot([-1, 3.5], [chance_level, chance_level], '--', color='k', zorder=-10)
ax1.set(ylabel='Decoding accuracy', xlim=[-0.8, 2.4], ylim=[-0.1, 0.62])
ax1.set_xticklabels(['Positive\ncontrol', 'Shuffle', 'Mouse\nbehavior'],
                    rotation=90, ha='center')
plt.tight_layout()
sns.despine(trim=True)

plt.savefig(join(FIG_PATH, 'suppfig_decoding_first_biased.pdf'))
plt.savefig(join(FIG_PATH, 'suppfig_decoding_first_biased.png'), dpi=300)


# %%
f, ax1 = plt.subplots(1, 1, figsize=(FIGURE_WIDTH/4, FIGURE_HEIGHT))
n_labs = decoding_result['confusion_matrix'][0].shape[0]
sns.heatmap(data=decoding_result['confusion_matrix'].mean(), vmin=0, vmax=0.4)
ax1.plot([0, 7], [0, 7], '--w')
ax1.set(xticklabels=np.arange(1, n_labs + 1), yticklabels=np.arange(1, n_labs + 1),
        ylim=[0, n_labs], xlim=[0, n_labs],
        title='', ylabel='Actual lab', xlabel='Predicted lab')
plt.setp(ax1.xaxis.get_majorticklabels(), rotation=40)
plt.setp(ax1.yaxis.get_majorticklabels(), rotation=40)
plt.gca().invert_yaxis()
plt.tight_layout()

plt.savefig(join(FIG_PATH, 'suppfig_confusion_matrix_first_biased.pdf'))
plt.savefig(join(FIG_PATH, 'suppfig_confusion_matrix_first_biased.png'), dpi=300)
back to top