In [1]:
# Import libraries
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import seaborn as sns
import numpy as np
from sklearn.metrics import confusion_matrix
In [2]:
# load pro/ret, trial type and choice data
tt = pd.read_csv('~/work/whiskfree/data/tt_36_subset_sorted.csv',header=None)
ch = pd.read_csv('~/work/whiskfree/data/ch_36_subset_sorted.csv',header=None)
proret = pd.read_csv('~/work/whiskfree/data/proret_36_subset_sorted.csv',header=None)
tt = tt.values.reshape(-1,1)
ch = ch.values.reshape(-1,1)
proret = proret.values.reshape(-1,1)
In [3]:
cm_tt = confusion_matrix(tt,proret)
In [4]:
def labelled_image(cm):
with sns.axes_style("white"):
plt.imshow(cm,interpolation='none')
for i in range(0,3):
for j in range(0,3):
plt.text(j, i, "{0:.2f}".format(cm[i,j]), va='center', ha='center',bbox=dict(facecolor='white',edgecolor='white', alpha=0.5))
xlabels = ['Retraction','Protraction','No Touch']
ylabels = ['Posterior','Anterior','No Go']
plt.title('Touch type | Trial type')
plt.xlabel('Touch type')
plt.ylabel('Trial type')
plt.xticks([0,1,2],xlabels)
plt.yticks([0,1,2],ylabels)
In [5]:
labelled_image(cm_tt)
In [30]:
cm_tt/np.sum(cm_tt)
Out[30]:
In [31]:
print(cm_tt)
print(sum(cm_tt.T))
In [6]:
norm_cm_tt = cm_tt.T/sum(cm_tt.T)
In [7]:
norm_cm_tt = norm_cm_tt.T
In [36]:
198/(198+28+83)
81/(81+110+66)
Out[36]:
In [8]:
labelled_image(norm_cm_tt)
plt.title('P(Touch type|Trial type)')
Out[8]:
In [9]:
norm_cm_tch = cm_tt/sum(cm_tt)
labelled_image(norm_cm_tch)
plt.title('P(Trial type | Touch type)')
Out[9]:
In [10]:
ch_given_ttpr = np.zeros([3,3,3])
for i in range(len(tt)):
tt_i = tt[i]
ch_i = ch[i]
pr_i = proret[i]
ch_given_ttpr[tt_i-1,pr_i-1,ch_i-1] += 1
In [11]:
x = plt.hist(ch)
In [14]:
labelled_image(ch_given_ttpr[:,:,0])
plt.title('Trial type | Touch type, Choice = 0')
print(np.sum(ch_given_ttpr[:,:,0]))
In [15]:
labelled_image(ch_given_ttpr[:,:,1])
plt.title('Trial type | Touch type, Choice = 1')
print(np.sum(ch_given_ttpr[:,:,1]))
In [16]:
labelled_image(ch_given_ttpr[:,:,2])
plt.title('Trial type | Touch type, Choice = 2')
print(np.sum(ch_given_ttpr[:,:,2]))
In [63]:
for i in range(3):
print(i)
In [76]:
plt.plot(ch[:100])
Out[76]:
In [80]:
labelled_image(confusion_matrix(tt,ch))
plt.xticks([0,1,2],ylabels)
Out[80]:
In [ ]: