Sebastian Hell contact@sebastianhell.com
import numpy as np
import pandas as pd
import os
import pickle
from scipy import stats
# setup paths
path = ' /dat/'
(_, dirnames, filenames) = os.walk(path).next()
filelabel = ['Label27.txt', 'Label28.txt',
'Label32.txt', 'Label37.txt', 'Label40.txt']
pathL = '/Label/'
# inti Dataframe
Dataset = pd.DataFrame()
# creating column names
joints = 'SpineBase SpineMid Neck Head ShoulderLeft ElbowLeft WristLeft HandLeft ShoulderRight ElbowRight WristRight HandRight HipLeft KneeLeft AnkleLeft FootLeft HipRight KneeRight AnkleRight FootRight SpineShoulder HandTipLeft ThumbLeft HandTipRight ThumbRight'.split(' ')
columnS = ['MaxP', 'BodyNum', 'Time']
for item in joints:
list.append(columnS, item + '_x')
list.append(columnS, item + '_y')
list.append(columnS, item + '_z')
list.append(columnS, item + '_state')
list.append(columnS, 'Testperson')
list.append(columnS, 'Label')
# loop over skeleton files
for fi in filenames:
print(fi)
data = np.loadtxt(path + fi, delimiter=',').T
pers = np.ones([1, data.shape[1]]) * int(fi[-6:-4])
LabDum = np.ones([1, data.shape[1]]) * np.NaN
data = np.append(data, pers, axis=0)
data = np.append(data, LabDum, axis=0)
# compare label files with skelton if there are lables available
for items in filelabel:
if fi[-6:-4] == items[-6:-4]:
Lab = np.array(np.loadtxt(pathL + items, delimiter=','))
data[-1, :] = Lab
else:
pass
dfTemp = pd.DataFrame(data.T, columns=columnS)
Dataset = Dataset.append(dfTemp, ignore_index=True)
#"write"
with pd.HDFStore('/FullDataset.h5', mode='w') as store:
store.append('RRRU', Dataset, data_columns=Dataset.columns, format='table')
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
with pd.HDFStore('/FullDataset.h5', mode='r') as newstore:
Dataset = newstore.select('RRRU')
Dataset[0:3]
Label | Action |
---|---|
1 | wait |
2 | work |
3 | fetch |
4 | Tab |
5 | undefined |
9 | untracked |
dfa = Dataset.query('Label == 1')[
['HandRight_x', 'HandRight_y', 'HandRight_z']]
dfb = Dataset.query(' Label == 2')[
['HandRight_x', 'HandRight_y', 'HandRight_z']]
idmin = np.min([dfb.shape[0], dfa.shape[0]])
df = pd.concat([dfa.sample(n=idmin, random_state=1),
dfb.sample(n=idmin, random_state=1)])
sns.set(style="white")
g = sns.PairGrid(Dataset[['HandRight_x', 'HandRight_y', 'HandRight_z']].sample(n=50000, random_state=1), diag_sharey=False)
g.map_lower(sns.kdeplot,rasterized=True, cmap="Blues_d")
g.map_upper(plt.scatter,s = 10,alpha =0.3)
g.map_diag(sns.kdeplot, lw=2,)
g.axes[0,0].yaxis.set_label_text('x (m)')
g.axes[1,0].yaxis.set_label_text('y (m)')
g.axes[2,0].yaxis.set_label_text('z (m)')
g.axes[2,0].xaxis.set_label_text('x (m)')
g.axes[2,1].xaxis.set_label_text('y (m)')
g.axes[2,2].xaxis.set_label_text('z (m)')
#plt.savefig('full.pdf')
sns.set(style="white")
g = sns.PairGrid(df, diag_sharey=False)
g.map_lower(sns.kdeplot,rasterized=True, cmap="Blues_d")
g.map_upper(plt.scatter,s = 10,alpha =0.3)
g.map_diag(sns.kdeplot, lw=2,)
g.axes[0,0].yaxis.set_label_text('x (m)')
g.axes[1,0].yaxis.set_label_text('y (m)')
g.axes[2,0].yaxis.set_label_text('z (m)')
g.axes[2,0].xaxis.set_label_text('x (m)')
g.axes[2,1].xaxis.set_label_text('y (m)')
g.axes[2,2].xaxis.set_label_text('z (m)')
df = Dataset.query('(((HandRight_x < 0.24)|(HandRight_x > 0.282)) |((HandRight_z < 0.58)|(HandRight_z > 0.62))|((HandRight_y < -0.061)|(HandRight_y > -0.039)))&(Label != 9) ' )
dfclear = df
df = df[['HandRight_x','HandRight_y','HandRight_z']].sample(n= 50000,random_state = 1)
dfclear.shape
sns.set(style="white")
g = sns.PairGrid(df, diag_sharey=False)
g.map_lower(sns.kdeplot,rasterized=True, cmap="Blues_d")
g.map_upper(plt.scatter,s = 10,alpha =0.3)
g.map_diag(sns.kdeplot, lw=2,)
g.axes[0,0].yaxis.set_label_text('x (m)')
g.axes[1,0].yaxis.set_label_text('y (m)')
g.axes[2,0].yaxis.set_label_text('z (m)')
g.axes[2,0].xaxis.set_label_text('x (m)')
g.axes[2,1].xaxis.set_label_text('y (m)')
g.axes[2,2].xaxis.set_label_text('z (m)')
plt.savefig('redu.pdf')
sns.set(style="white")
dfbla = Dataset.query('Label == 3')[
['HandRight_x', 'HandRight_y', 'HandRight_z']]
dfblb = Dataset.query(' Label == 4')[
['HandRight_x', 'HandRight_y', 'HandRight_z']]
idmin = np.min([dfbla.shape[0], dfblb.shape[0]])
dfH = pd.concat([dfbla.sample(n=idmin, random_state=1),
dfblb.sample(n=idmin, random_state=1)])
g = sns.PairGrid(dfH, diag_sharey=False)
g.map_lower(sns.kdeplot,rasterized=True, cmap="Blues_d")
g.map_upper(plt.scatter,s = 10,alpha =0.3)
g.map_diag(sns.kdeplot, lw=2,)
g.axes[0,0].yaxis.set_label_text('x (m)')
g.axes[1,0].yaxis.set_label_text('y (m)')
g.axes[2,0].yaxis.set_label_text('z (m)')
g.axes[2,0].xaxis.set_label_text('x (m)')
g.axes[2,1].xaxis.set_label_text('y (m)')
g.axes[2,2].xaxis.set_label_text('z (m)')
plt.savefig('Tippen_Holen.pdf')
dfH.shape
Compare if Datsetsize Changes KDE alot
df = dfclear[['HandRight_x','HandRight_y','HandRight_z']]
sns.distplot(df.sample(n = 100,random_state= 1).HandRight_x, hist=False, rug=True, color="r")
sns.distplot(df.sample(n = 1000,random_state= 1).HandRight_z, hist=False, rug=True, color="r")
sns.distplot(df.sample(n = 1000,random_state= 1).HandRight_y, hist=False, rug=True, color="r")
Looking at Lefthand Data
sns.distplot(dfclear.sample(n = 1000,random_state= 1).HandLeft_y, hist=False, rug=True, color="r")
Looking at Lefthand Data
df = Dataset.query('((HandLeft_y > 0)) ' )
sns.distplot(df.sample(n = 1000,random_state= 1).HandLeft_y, hist=False, rug=True, color="r")
dfLabel= Dataset[pd.notnull(Dataset['Label'])]
df = dfLabel.query('((Label != 9)&(Label != 5))')
dfa = Dataset.query('Label == 1' )
dfb = Dataset.query(' Label == 2' )
dfc = Dataset.query(' Label == 3' )
dfd = Dataset.query(' Label == 4' )
idmin = np.min([dfb.shape[0],dfa.shape[0],dfc.shape[0],dfd.shape[0]])
df= pd.concat([dfa.sample(n= idmin,random_state = 1),dfb.sample(n=idmin,random_state = 1),dfc.sample(n=idmin,random_state = 1),dfd.sample(n=idmin,random_state = 1)])
print(idmin)
print([dfa.shape[0],dfb.shape[0],dfc.shape[0],dfd.shape[0]])
Variabl | Label |
---|---|
dfa | wait |
dfb | work |
dfc | fetch |
dfd | Tab |
sns.set(style="white")
g = sns.PairGrid(df[['HandRight_x','HandRight_y','HandRight_z']], diag_sharey=False)
g.map_lower(sns.kdeplot,rasterized=True, cmap="Blues_d")
g.map_upper(plt.scatter,s = 10,alpha =0.3)
g.map_diag(sns.kdeplot, lw=2,)
g.axes[0,0].yaxis.set_label_text('x (m)')
g.axes[1,0].yaxis.set_label_text('y (m)')
g.axes[2,0].yaxis.set_label_text('z (m)')
g.axes[2,0].xaxis.set_label_text('x (m)')
g.axes[2,1].xaxis.set_label_text('y (m)')
g.axes[2,2].xaxis.set_label_text('z (m)')
plt.savefig('evenSamples.pdf')
f, axes = plt.subplots(1, 3, figsize=(21, 6))
sns.distplot(dfa.sample(n = idmin ,random_state= 1).HandRight_x, hist=False, rug=True, color="r", ax = axes[0])
sns.distplot(dfa.sample(n = idmin ,random_state= 1).HandRight_y, hist=False, rug=True, color="r", ax = axes[1])
sns.distplot(dfa.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, rug=True, color="r", ax = axes[2])
f, axes = plt.subplots(1, 3, figsize=(21, 6))
sns.distplot(dfb.sample(n = idmin ,random_state= 1).HandRight_x, hist=False, rug=True, color="r", ax = axes[0])
sns.distplot(dfb.sample(n = idmin ,random_state= 1).HandRight_y, hist=False, rug=True, color="r", ax = axes[1])
sns.distplot(dfb.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, rug=True, color="r", ax = axes[2])
f, axes = plt.subplots(1, 3, figsize=(21, 6))
sns.distplot(dfc.sample(n = idmin ,random_state= 1).HandRight_x, hist=False, rug=True, color="r", ax = axes[0])
sns.distplot(dfc.sample(n = idmin ,random_state= 1).HandRight_y, hist=False, rug=True, color="r", ax = axes[1])
sns.distplot(dfc.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, rug=True, color="r", ax = axes[2])
f, axes = plt.subplots(1, 3, figsize=(21, 6))
sns.distplot(dfd.sample(n = idmin ,random_state= 1).HandRight_x, hist=False, rug=True, color="r", ax = axes[0])
sns.distplot(dfd.sample(n = idmin ,random_state= 1).HandRight_y, hist=False, rug=True, color="r", ax = axes[1])
sns.distplot(dfd.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, rug=True, color="r", ax = axes[2])
f, axes = plt.subplots(1, 3, figsize=(27, 6))
sns.set(style="darkgrid", color_codes=True)
sns.distplot(dfa.sample(n = idmin ,random_state= 1).HandRight_x, hist=False,color="r", ax = axes[0],label = 'Rest')
sns.distplot(dfb.sample(n = idmin ,random_state= 1).HandRight_x, hist=False, color="g", ax = axes[0],label = 'Work')
sns.distplot(dfc.sample(n = idmin ,random_state= 1).HandRight_x, hist=False,color="b", ax = axes[0],label = 'Fetch')
sns.distplot(dfd.sample(n = idmin ,random_state= 1).HandRight_x, hist=False, color="k", ax = axes[0],label = 'Tab')
axes[0].legend(frameon=True,fontsize=14)
axes[0].xaxis.set_label_text('x (m)',fontsize=15)
axes[0].tick_params(axis='x',labelsize=12)
axes[0].tick_params(axis='y',labelsize=12)
sns.distplot(dfa.sample(n = idmin ,random_state= 1).HandRight_y, hist=False, color="r", ax = axes[1],label = 'Rest')
sns.distplot(dfb.sample(n = idmin ,random_state= 1).HandRight_y, hist=False, color="g", ax = axes[1],label = 'Work')
sns.distplot(dfc.sample(n = idmin ,random_state= 1).HandRight_y, hist=False,color="b", ax = axes[1],label = 'Fetch')
sns.distplot(dfd.sample(n = idmin ,random_state= 1).HandRight_y, hist=False,color="k", ax = axes[1],label = 'Tab')
axes[1].legend(frameon=True,fontsize=14)
axes[1].xaxis.set_label_text('y (m)',fontsize=15)
axes[1].tick_params(axis='x',labelsize=12)
axes[1].tick_params(axis='y',labelsize=12)
sns.distplot(dfa.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, color="r", ax = axes[2],label = 'Rest')
sns.distplot(dfb.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, color="g", ax = axes[2],label = 'Work')
sns.distplot(dfc.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, color="b", ax = axes[2],label = 'Fetch')
sns.distplot(dfd.sample(n = idmin ,random_state= 1).HandRight_z, hist=False, color="k", ax = axes[2],label = 'Tab')
axes[2].legend(frameon=True,fontsize=14)
axes[2].xaxis.set_label_text('z (m)',fontsize=15)
axes[2].tick_params(axis='x',labelsize=12)
axes[2].tick_params(axis='y',labelsize=12)
plt.savefig('actionDensityxyz.pdf')
Evaluation of the Plots
Matrix shows along which axes to actions are good to seperate. The tilde ~ stands for semi-good
from matplotlib.colors import LinearSegmentedColormap
fig, ax = plt.subplots()
min_val, max_val, diff = 0., 4., 1.
bababa = np.array([[' ','~x\n~y\n~z','y\nz','x'],['~x\n~y\n~z',' ',' z\n~x\n~y',' x\n~z'],['y\nz',' z\n~x\n~y',' ','x\ny\nz'],['x',' x\n~z','x\ny\nz','']])
#imshow portion
N_points = 4
#imshow_data = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])
imshow_data = np.array([[[0,0.4,0],[1,1,0.6],[0.6,1,0.6],[0.9,1,0.6]],[[1,1,0.6],[0,0.4,0],[0.6,1,0.6],[0.8,1,0.6]],[[0.6,1,0.6],[0.6,1,0.6],[0,0.4,0],[0.6,1,0.6]],[[0.9,1,0.6],[0.8,1,0.6],[0.6,1,0.6],[0,0.4,0]]])
colors = [ (1,1,0.6),(0.6,1,0.6) ]
n_bin = 100
cmap_name = 'my_list'
cm = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bin)
cax = ax.imshow(imshow_data, interpolation='nearest',cmap=cm)
#ax.pcolor(imshow_data, cmap=plt.cm.Blues)
#text portion
ind_array = np.arange(min_val, max_val, diff)
x, y = np.meshgrid(ind_array, ind_array)
i = 0
b = bababa.flatten()
for x_val, y_val in zip(x.flatten(), y.flatten()):
c= b[i]
ax.text(x_val, y_val, c, va='center', ha='center')
i+= 1
# #set tick marks for grid
# ax.set_xticks(np.arange(min_val-diff/2, max_val-diff/2))
# ax.set_yticks(np.arange(min_val-diff/2, max_val-diff/2))
# ax.set_xticklabels(['Rest','Work','Fetch','Tab'])
# ax.set_yticklabels(['Rest','Work','Fetch','Tab'])
# ax.set_xlim(min_val-diff/2, max_val-diff/2)
# ax.set_ylim(min_val-diff/2, max_val-diff/2)
labels =['Rest','Work','Fetch','Tab']
for axis in [ax.xaxis, ax.yaxis]:
axis.set(ticks=np.arange(0, len(labels)), ticklabels=labels)
#ax.invert_yaxis()
ax.xaxis.tick_top()
ax.grid(which='major')
ax.set_xticks(np.arange(-.5, 4, 1), minor=True);
ax.set_yticks(np.arange(-.5, 4, 1), minor=True);
ax.grid(which='minor', color='k', linestyle='-', linewidth=1)
cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
cbar.ax.set_yticklabels([ 'medium \nseparable', 'well \nseparable']) # vertically oriented colorbar
plt.savefig('matrix.pdf')
plt.show()
Best Tab and Fetch, worst Work and Rest
f, axes = plt.subplots(1, 3, figsize=(27, 6))
sns.set(style="darkgrid", color_codes=True)
sns.distplot(dfa.sample(n = 12575 ,random_state= 1).HandRight_x, hist=False,color="r", ax = axes[0],label = 'Rest')
sns.distplot(dfb.sample(n = 12575 ,random_state= 1).HandRight_x, hist=False, color="g", ax = axes[0],label = 'Work')
axes[0].legend(frameon=True,fontsize=14)
axes[0].xaxis.set_label_text('x (m)',fontsize=15)
axes[0].tick_params(axis='x',labelsize=12)
axes[0].tick_params(axis='y',labelsize=12)
sns.distplot(dfa.sample(n = 12575 ,random_state= 1).HandRight_y, hist=False, color="r", ax = axes[1],label = 'Rest')
sns.distplot(dfb.sample(n = 12575 ,random_state= 1).HandRight_y, hist=False, color="g", ax = axes[1],label = 'Work')
axes[1].legend(frameon=True,fontsize=14)
axes[1].xaxis.set_label_text('y (m)',fontsize=15)
axes[1].tick_params(axis='x',labelsize=12)
axes[1].tick_params(axis='y',labelsize=12)
sns.distplot(dfa.sample(n = 12575 ,random_state= 1).HandRight_z, hist=False, color="r", ax = axes[2],label = 'Rest')
sns.distplot(dfb.sample(n = 12575 ,random_state= 1).HandRight_z, hist=False, color="g", ax = axes[2],label = 'Work')
axes[2].legend(frameon=True,fontsize=14)
axes[2].xaxis.set_label_text('z (m)',fontsize=15)
axes[2].tick_params(axis='x',labelsize=12)
axes[2].tick_params(axis='y',labelsize=12)
a = np.array([-200,-100,-100,-100,-100,100,100,100,100,100,100])
from scipy import stats
data = dfa.sample(n = 1000 ,random_state= 1).HandRight_x
b = stats.gaussian_kde(data,bw_method=0.1)
bla = np.array(data)
bla = np.sort(bla)
out = b(bla)
out = out / np.max(out)
plt.plot(bla,out)
plt.show()
sns.distplot(data)
print(b.integrate_box_1d(-0.1,0.5))
print(b(data.mean()))
print(np.max(out))
Heatmap wit same sample size in every class
import matplotlib.image as mpimg
img=mpimg.imread('FrontLabel4Color.png')
f, ax = plt.subplots(figsize=(8,8), ncols=2, nrows=2)
#ax.set_ylim(bottom=0.5, top=1.4)
#ax.set_xlim(left=0.5, right=1.4)
dfa = df.query('Label==1')
dfb = df.query('Label==2')
dfc = df.query('Label==3')
dfd = df.query('Label==4')
#xz
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_z,cmap="Reds", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_z,cmap="Blues", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_z,cmap="Greens", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_z,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[1][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[1][0].text(-0.06,0.8, "Work", size=16, color=blue)
ax[1][0].text(0.31, 1.18, "Rest", size=16, color=red)
ax[1][0].text(0.09, 0.6, "Fetch", size=16, color= green)
ax[1][0].text(0.5, 1, "Tab", size=16, color= pink)
ax[1][0].set(xlabel='x (m)', ylabel='z (m)')
ax[1][0].xaxis.label.set_size(15)
ax[1][0].yaxis.label.set_size(15)
ax[1][0].tick_params(axis='x',labelsize=12)
ax[1][0].tick_params(axis='y',labelsize=12)
ax[1][0].set_ylim(bottom=1.3, top=0.5)
ax[1][0].set_xlim(left=-0.2, right=0.6)
#f.savefig('KdeXZ.pdf')
#zy
sns.kdeplot(dfd.HandRight_z, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfa.HandRight_z, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfc.HandRight_z, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfb.HandRight_z, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][1])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][1].text(1.01,0.027, "Work", size=16, color=blue)
ax[0][1].text(1.16, -0.24, "Rest", size=16, color=red)
ax[0][1].text(0.67, 0.043, "Fetch", size=16, color= green)
#ax.text(0.52, -0.1, "Tab", size=16, color= pink)
ax[0][1].set(xlabel='z (m)', ylabel='')
ax[0][1].xaxis.label.set_size(15)
ax[0][1].tick_params(axis='x',labelsize=12)
ax[0][1].tick_params(axis='y',labelsize=12,label1On = False)
ax[0][1].set_xlim(left=0.4, right=1.4)
ax[0][1].set_ylim(bottom=-0.3, top=0.2)
#ax[0][1].yaxis.set_visible(False)
#f.savefig('KdeZY.pdf')
#xy
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][0].text(0.06,0.05, "Work", size=16, color=blue)
ax[0][0].text(0.2, -0.27, "Rest", size=16, color=red)
ax[0][0].text(0.36, 0.02, "Fetch", size=16, color= green)
ax[0][0].text(0.49, -0.1, "Tab", size=16, color= pink)
ax[0][0].set(xlabel='', ylabel='y (m)')
ax[0][0].set_xlim(left=-0.2, right=0.6)
ax[0][0].set_ylim(bottom=-0.3, top=0.2)
#ax[0][0].xaxis.set_visible(False)
ax[0][0].yaxis.label.set_size(15)
ax[0][0].tick_params(axis='x',labelsize=12,label1On = False)
ax[0][0].tick_params(axis='y',labelsize=12)
plt.imshow(img,axes=ax[1][1])
ax[1][1].xaxis.set_visible(False)
ax[1][1].yaxis.set_visible(False)
#ax[-1,-1].axis('off')
f.savefig('KdeSubplotsBlend.pdf')
np.random.seed(seed=4)
dataset = np.random.randn(4)
f, ax = plt.subplots(1, 1)
sns.rugplot(dataset,ax=ax)
plt.ylim(0,2)
sns.rugplot(dataset)
x_min = dataset.min() - 2
x_max = dataset.max() + 2
#100 equally spaced points from x_min to x_max
x_axis = np.linspace(x_min,x_max,100)
#bandwidth is a smooth factor
bandwidth = ((4*dataset.std()**5)/(3*len(dataset)))**.2
#create an empty kernel list
kernel_list = []
#plot each basis function
for data_point in dataset:
#create a kernel for each point and append to list
kernel = stats.norm(data_point,bandwidth).pdf(x_axis)
kernel_list.append(kernel)
#scale for plotting
kernel = kernel/kernel.max()
kernel = kernel*.4
plt.plot(x_axis,kernel,color='black',alpha=1)
plt.ylim(0,2.1)
plt.plot(x_axis,kernel,color='black',alpha=1,label='Kernel')
sum_of_kde = np.sum(kernel_list,axis=0)
fig = plt.plot(x_axis,sum_of_kde,color='indianred',axes=ax,label='KDE')
sns.rugplot(dataset,c = 'indianred',ax=ax)
sns.rugplot(dataset[0:1],c = 'indianred',ax=ax,label='Datapoints')
plt.yticks()
ax.legend()
plt.savefig('KDEex.pdf')
with pd.HDFStore('/Hell.h5', mode='r') as newstore:
DataMod = newstore.select('RRRU')
DataMod.columns = ['HeadPos_x', 'HeadPos_y','HeadPos_z','HandLeft_x' ,'HandLeft_y', 'HandLeft_z' ,'HandRight_x' ,'HandRight_y' ,'HandRight_z' ,'Label' ,'Person' ,'serial']
mask = DataMod['Person']=='0'
DataMod.loc[mask,['HeadPos_x','HandLeft_x','HandRight_x' ]]= DataMod.loc[mask,['HeadPos_x','HandLeft_x','HandRight_x' ]].mul(-1)
DataHell = DataMod.query('Person=="Hell"')
DataMod0 = DataMod.query('Person=="0"')
f, ax = plt.subplots(figsize=(8,8), ncols=2, nrows=2)
#ax.set_ylim(bottom=0.5, top=1.4)
#ax.set_xlim(left=0.5, right=1.4)
dfa = DataMod.query('Label==1')
dfb = DataMod.query('Label==2')
dfc = DataMod.query('Label==3')
dfd = DataMod.query('Label==4')
#xz
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_z,cmap="Reds", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_z,cmap="Blues", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_z,cmap="Greens", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_z,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[1][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[1][0].text(-0.06,0.8, "Work", size=16, color=blue)
ax[1][0].text(0.31, 1.18, "Rest", size=16, color=red)
ax[1][0].text(0.09, 0.6, "Fetch", size=16, color= green)
ax[1][0].text(0.5, 1, "Tab", size=16, color= pink)
ax[1][0].set(xlabel='x (m)', ylabel='z (m)')
ax[1][0].xaxis.label.set_size(15)
ax[1][0].yaxis.label.set_size(15)
ax[1][0].tick_params(axis='x',labelsize=12)
ax[1][0].tick_params(axis='y',labelsize=12)
ax[1][0].set_ylim(bottom=1.3, top=0.5)
ax[1][0].set_xlim(left=-0.2, right=0.6)
#f.savefig('KdeXZ.pdf')
#zy
sns.kdeplot(dfd.HandRight_z, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfa.HandRight_z, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfc.HandRight_z, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfb.HandRight_z, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][1])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][1].text(1.01,0.027, "Work", size=16, color=blue)
ax[0][1].text(1.16, -0.24, "Rest", size=16, color=red)
ax[0][1].text(0.67, 0.043, "Fetch", size=16, color= green)
#ax.text(0.52, -0.1, "Tab", size=16, color= pink)
ax[0][1].set(xlabel='z (m)', ylabel='')
ax[0][1].xaxis.label.set_size(15)
ax[0][1].tick_params(axis='x',labelsize=12)
ax[0][1].tick_params(axis='y',labelsize=12,label1On = False)
ax[0][1].set_xlim(left=0.4, right=1.4)
ax[0][1].set_ylim(bottom=-0.3, top=0.2)
#ax[0][1].yaxis.set_visible(False)
#f.savefig('KdeZY.pdf')
#xy
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][0].text(0.06,0.05, "Work", size=16, color=blue)
ax[0][0].text(0.2, -0.27, "Rest", size=16, color=red)
ax[0][0].text(0.36, 0.02, "Fetch", size=16, color= green)
ax[0][0].text(0.49, -0.1, "Tab", size=16, color= pink)
ax[0][0].set(xlabel='', ylabel='y (m)')
ax[0][0].set_xlim(left=-0.2, right=0.6)
ax[0][0].set_ylim(bottom=-0.3, top=0.2)
#ax[0][0].xaxis.set_visible(False)
ax[0][0].yaxis.label.set_size(15)
ax[0][0].tick_params(axis='x',labelsize=12,label1On = False)
ax[0][0].tick_params(axis='y',labelsize=12)
ax[-1,-1].axis('off')
#f.savefig('KdeSubplotsBlend.pdf')
f, ax = plt.subplots(figsize=(8,8), ncols=2, nrows=2)
#ax.set_ylim(bottom=0.5, top=1.4)
#ax.set_xlim(left=0.5, right=1.4)
dfa = DataHell.query('Label==1')
dfb = DataHell.query('Label==2')
dfc = DataHell.query('Label==3')
dfd = DataHell.query('Label==4')
#xz
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_z,cmap="Reds", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_z,cmap="Blues", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_z,cmap="Greens", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_z,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[1][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[1][0].text(-0.06,0.8, "Work", size=16, color=blue)
ax[1][0].text(0.31, 1.18, "Rest", size=16, color=red)
ax[1][0].text(0.09, 0.6, "Fetch", size=16, color= green)
ax[1][0].text(0.5, 1, "Tab", size=16, color= pink)
ax[1][0].set(xlabel='x (m)', ylabel='z (m)')
ax[1][0].xaxis.label.set_size(15)
ax[1][0].yaxis.label.set_size(15)
ax[1][0].tick_params(axis='x',labelsize=12)
ax[1][0].tick_params(axis='y',labelsize=12)
ax[1][0].set_ylim(bottom=1.3, top=0.5)
#ax[1][0].set_xlim(left=-0.2, right=0.6)
#f.savefig('KdeXZ.pdf')
#zy
sns.kdeplot(dfd.HandRight_z, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfa.HandRight_z, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfc.HandRight_z, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfb.HandRight_z, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][1])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][1].text(1.01,0.027, "Work", size=16, color=blue)
ax[0][1].text(1.16, -0.24, "Rest", size=16, color=red)
ax[0][1].text(0.67, 0.043, "Fetch", size=16, color= green)
#ax.text(0.52, -0.1, "Tab", size=16, color= pink)
ax[0][1].set(xlabel='z (m)', ylabel='')
ax[0][1].xaxis.label.set_size(15)
ax[0][1].tick_params(axis='x',labelsize=12)
ax[0][1].tick_params(axis='y',labelsize=12,label1On = False)
ax[0][1].set_xlim(left=0.4, right=1.4)
ax[0][1].set_ylim(bottom=-0.3, top=0.2)
#ax[0][1].yaxis.set_visible(False)
#f.savefig('KdeZY.pdf')
#xy
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][0].text(0.06,0.05, "Work", size=16, color=blue)
ax[0][0].text(0.2, -0.27, "Rest", size=16, color=red)
ax[0][0].text(0.36, 0.02, "Fetch", size=16, color= green)
ax[0][0].text(0.49, -0.1, "Tab", size=16, color= pink)
ax[0][0].set(xlabel='', ylabel='y (m)')
ax[0][0].set_xlim(left=-0.2, right=0.6)
ax[0][0].set_ylim(bottom=-0.3, top=0.2)
#ax[0][0].xaxis.set_visible(False)
ax[0][0].yaxis.label.set_size(15)
ax[0][0].tick_params(axis='x',labelsize=12,label1On = False)
ax[0][0].tick_params(axis='y',labelsize=12)
ax[-1,-1].axis('off')
#f.savefig('KdeSubplotsBlend.pdf')
f, ax = plt.subplots(figsize=(8,8), ncols=2, nrows=2)
#ax.set_ylim(bottom=0.5, top=1.4)
#ax.set_xlim(left=0.5, right=1.4)
dfa = DataMod0.query('Label==1')
dfb = DataMod0.query('Label==2')
dfc = DataMod0.query('Label==3')
dfd = DataMod0.query('Label==4')
#xz
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_z,cmap="Reds", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_z,cmap="Blues", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_z,cmap="Greens", shade=True, shade_lowest=False,ax=ax[1][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_z,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[1][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[1][0].text(-0.06,0.8, "Work", size=16, color=blue)
ax[1][0].text(0.31, 1.18, "Rest", size=16, color=red)
ax[1][0].text(0.09, 0.6, "Fetch", size=16, color= green)
ax[1][0].text(0.5, 1, "Tab", size=16, color= pink)
ax[1][0].set(xlabel='x (m)', ylabel='z (m)')
ax[1][0].xaxis.label.set_size(15)
ax[1][0].yaxis.label.set_size(15)
ax[1][0].tick_params(axis='x',labelsize=12)
ax[1][0].tick_params(axis='y',labelsize=12)
ax[1][0].set_ylim(bottom=1.3, top=0.5)
#ax[1][0].set_xlim(left=-0.2, right=0.6)
#f.savefig('KdeXZ.pdf')
#zy
sns.kdeplot(dfd.HandRight_z, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfa.HandRight_z, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfc.HandRight_z, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][1])
sns.kdeplot(dfb.HandRight_z, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][1])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][1].text(1.01,0.027, "Work", size=16, color=blue)
ax[0][1].text(1.16, -0.24, "Rest", size=16, color=red)
ax[0][1].text(0.67, 0.043, "Fetch", size=16, color= green)
#ax.text(0.52, -0.1, "Tab", size=16, color= pink)
ax[0][1].set(xlabel='z (m)', ylabel='')
ax[0][1].xaxis.label.set_size(15)
ax[0][1].tick_params(axis='x',labelsize=12)
ax[0][1].tick_params(axis='y',labelsize=12,label1On = False)
#ax[0][1].set_xlim(left=0.4, right=1.4)
#ax[0][1].set_ylim(bottom=-0.3, top=0.2)
#ax[0][1].yaxis.set_visible(False)
#f.savefig('KdeZY.pdf')
#xy
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_y,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_y,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_y,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0][0])
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_y,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0][0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0][0].text(0.06,0.05, "Work", size=16, color=blue)
ax[0][0].text(0.2, -0.27, "Rest", size=16, color=red)
ax[0][0].text(0.36, 0.02, "Fetch", size=16, color= green)
ax[0][0].text(0.49, -0.1, "Tab", size=16, color= pink)
ax[0][0].set(xlabel='', ylabel='y (m)')
#ax[0][0].set_xlim(left=-0.2, right=0.6)
#ax[0][0].set_ylim(bottom=-0.3, top=0.2)
#ax[0][0].xaxis.set_visible(False)
ax[0][0].yaxis.label.set_size(15)
ax[0][0].tick_params(axis='x',labelsize=12,label1On = False)
ax[0][0].tick_params(axis='y',labelsize=12)
ax[-1,-1].axis('off')
#f.savefig('KdeSubplotsBlend.pdf')
f, ax = plt.subplots(figsize=(8,4), ncols=2, nrows=1)
#ax.set_ylim(bottom=0.5, top=1.4)
#ax.set_xlim(left=0.5, right=1.4)
dfa0 = DataMod0.query('Label==1')
dfb0 = DataMod0.query('Label==2')
dfc0 = DataMod0.query('Label==3')
dfd0 = DataMod0.query('Label==4')
dfa = DataMod.query('Label==1')
dfb = DataMod.query('Label==2')
dfc = DataMod.query('Label==3')
dfd = DataMod.query('Label==4')
sns.kdeplot(dfa0.HandRight_x, dfa0.HandRight_z,cmap="Reds", shade=True, shade_lowest=False,ax=ax[0])
sns.kdeplot(dfb0.HandRight_x, dfb0.HandRight_z,cmap="Blues", shade=True, shade_lowest=False,ax=ax[0])
sns.kdeplot(dfc0.HandRight_x, dfc0.HandRight_z,cmap="Greens", shade=True, shade_lowest=False,ax=ax[0])
sns.kdeplot(dfd0.HandRight_x, dfd0.HandRight_z,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[0])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[0].text(-0.06,0.8, "Work", size=16, color=blue)
ax[0].text(0.31, 1.18, "Rest", size=16, color=red)
ax[0].text(0.09, 0.6, "Fetch", size=16, color= green)
ax[0].text(0.5, 1, "Tab", size=16, color= pink)
ax[0].set(xlabel='x (m)', ylabel='z (m)')
ax[0].xaxis.label.set_size(15)
ax[0].yaxis.label.set_size(15)
ax[0].tick_params(axis='x',labelsize=12)
ax[0].tick_params(axis='y',labelsize=12)
ax[0].set_ylim(bottom=1.3, top=0.5)
ax[0].set_xlim(left=-0.2, right=0.6)
sns.kdeplot(dfd.HandRight_x, dfd.HandRight_z,cmap="BuPu", shade=True, shade_lowest=False,ax=ax[1])
sns.kdeplot(dfa.HandRight_x, dfa.HandRight_z,cmap="Reds", shade=True, shade_lowest=False,ax=ax[1])
sns.kdeplot(dfc.HandRight_x, dfc.HandRight_z,cmap="Greens", shade=True, shade_lowest=False,ax=ax[1])
sns.kdeplot(dfb.HandRight_x, dfb.HandRight_z,cmap="Blues", shade=True, shade_lowest=False,ax=ax[1])
red = sns.color_palette("Reds")[-2]
blue = sns.color_palette("Blues")[-2]
green = sns.color_palette("Greens")[-2]
pink = sns.color_palette("BuPu")[-2]
ax[1].text(-0.06,0.8, "Work", size=16, color=blue)
ax[1].text(0.31, 1.18, "Rest", size=16, color=red)
ax[1].text(0.09, 0.6, "Fetch", size=16, color= green)
ax[1].text(0.5, 1, "Tab", size=16, color= pink)
ax[1].set(xlabel='x (m)', ylabel='')
ax[1].xaxis.label.set_size(15)
ax[1].tick_params(axis='x',labelsize=12)
ax[1].tick_params(axis='y',labelsize=12,label1On = False)
ax[1].set_xlim(left=-0.2, right=0.6)
ax[1].set_ylim(bottom=1.3, top=0.5)
#f.savefig('OldVsNew.pdf')
print(dfa.shape[0]-dfa0.shape[0])
print(dfb.shape[0]-dfb0.shape[0])
print(dfc.shape[0]-dfc0.shape[0])
print(dfd.shape[0]-dfd0.shape[0])
print(dfa0.shape)
print(dfb0.shape)
print(dfc0.shape)
print(dfd0.shape)
3088 + 7140 + 2225 +1193