Skip to content

Instantly share code, notes, and snippets.

@3catz
Created November 19, 2020 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3catz/ca4d0021c8fe950b9eebcbe842157b99 to your computer and use it in GitHub Desktop.
Save 3catz/ca4d0021c8fe950b9eebcbe842157b99 to your computer and use it in GitHub Desktop.
acts = ["jogging","standing","downstairs","upstairs","walkfast","walkmod","walkslow","lying","sitting"]
def create_windows(subjects):
length = 100
stride = 50
sample = 10
framelist = []
targetlist = []
global acts
for act in acts:
for f in glob.glob(subjects + act):
d = pd.read_csv(f, header = None)
ns = len(d) // length
ns *= length
for i in range(0, ns - length, stride):
snap = d.iloc[i : i + length,:]
snap = snap.iloc[::sample,:] ;
framelist.append(snap)
targetlist.append(act)
X = np.stack(framelist)
Y = np.array(targetlist)
Y = pd.Series(Y)
Y = Y.astype("category")
Y = Y.cat.codes
#for i, j in zip(np.arange(9), Y.cat.categories):
# print(i,j)
x = np.ndarray.flatten(X)
x = np.reshape(x, newshape = (X.shape[0], X.shape[1] * X.shape[2]))
pd.DataFrame(x)
X = x
#print(X.shape, Y.shape)
Y = Y[:,np.newaxis]
return X, Y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment