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
walking_3_sec = data[(data['activity'] == 'walking') & (data['exp_id'] == 1)][1000:1150] | |
model.predict(walking_3_sec, output_frequency='per_window') |
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
# Save the model for later use in Turi Create | |
model.save('mymodel.model') | |
# Export for use in Core ML | |
model.export_coreml('MyActivityClassifier.mlmodel') |
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
# Evaluate the model and save the results into a dictionary | |
metrics = model.evaluate(test) | |
print(metrics['accuracy']) |
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
# Create an activity classifier | |
model = tc.activity_classifier.create(train, session_id='exp_id', target='activity', prediction_window=50) |
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
# Train/test split by recording sessions | |
train, test = tc.activity_classifier.util.random_split_by_session(data, session_id='exp_id', fraction=0.8) |
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
target_map = { | |
1.: 'walking', | |
2.: 'climbing_upstairs', | |
3.: 'climbing_downstairs', | |
4.: 'sitting', | |
5.: 'standing', | |
6.: 'laying' | |
} | |
# Use the same labels used in the experiment |
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
from glob import glob | |
acc_files = glob(data_dir + 'acc_*.txt') | |
gyro_files = glob(data_dir + 'gyro_*.txt') | |
# Load data | |
data = tc.SFrame() | |
files = zip(sorted(acc_files), sorted(gyro_files)) | |
for acc_file, gyro_file in files: | |
exp_id = int(acc_file.split('_')[1][-2:]) |
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
def find_label_for_containing_interval(intervals, index): | |
containing_interval = intervals[:, 0][(intervals[:, 1] <= index) & (index <= intervals[:, 2])] | |
if len(containing_interval) == 1: | |
return containing_interval[0] |
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
import turicreate as tc | |
data_dir = './HAPTdataset/RawData/' | |
# Load labels | |
labels = tc.SFrame.read_csv(data_dir + 'labels.txt', delimiter=' ', header=False, verbose=False) | |
labels = labels.rename({'X1': 'exp_id', 'X2': 'user_id', 'X3': 'activity_id', 'X4': 'start', 'X5': 'end'}) | |
labels |
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
#Uploading the Dataset | |
from google.colab import files | |
uploaded = files.upload() | |
with open("HAPTdataset.zip", 'w') as f: | |
f.write(uploaded[uploaded.keys()[0]]) | |
import zipfile |
NewerOlder