Created
November 19, 2020 22:46
-
-
Save 3catz/ca4d0021c8fe950b9eebcbe842157b99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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