import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()
data_0 = pd.read_csv("19-0.csv")
data_4 = pd.read_csv("19-4.csv")
data_8 = pd.read_csv("19-8.csv")
not_feature = ['ts','run','state','p-1','p-2','p-3','p-4','p-5','c161', 'Unnamed: 0']
feature_columns = [_ for _ in list(data_8.columns) if _ not in not_feature]
w = 10
h = 16
def mergeGrids(data):
#data: df with each state one sensor location
data = data.drop_duplicates(subset='state', keep="last")
data = data[data['state'] != 0 ]
res = np.zeros((h,w))
X = data[feature_columns].values
X = X.reshape((X.shape[0], w, h))
i = 0
for x in range(h):
#print(x)
for y in range(w):
#print(y)
res[x,y] = X[i].T[x,y]
i +=1
return res
grid4 = mergeGrids(data_4)
grid8 = mergeGrids(data_8)
sns.heatmap(grid8)
n = 160 * 13
target = np.empty(n)
x = data_0.loc[0,feature_columns].values.flatten()
plot = {
'0': x,
'4': grid4.flatten(),
'8': grid8.flatten()
}
plotdf = pd.DataFrame(plot)
sns.catplot(data=plotdf, kind="strip")
plotdf[0:10]
y = plotdf.values.reshape((160*3), order='F')
x = np.repeat([0.01,112,320], 160)
print(x.shape)
print(y.shape)
sns.regplot(x,y, logx = True);
plotdf.T
weight0=plotdf.T.iloc[0]
weight4=plotdf.T.iloc[1]
weight8=plotdf.T.iloc[2]
plt.plot(weight0,linestyle=':')
plt.plot(weight4,linestyle=':')
plt.plot(weight8,linestyle=':')