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
#Encoding Categorical Data | |
from sklearn.preprocessing import LabelEncoder | |
labelencoder = LabelEncoder() | |
y = labelencoder.fit_transform(y) |
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
# Importing the Keras libraries and packages | |
import keras | |
from keras.models import Sequential | |
from keras.layers import Dense |
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
# Initialising the ANN | |
classifier = Sequential() |
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
# Adding the input layer and the first hidden layer | |
classifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu', input_dim = 30)) | |
# Adding the second hidden layer | |
classifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu')) | |
# Adding the output layer | |
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) | |
# Compiling the ANN |
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
# Fitting the ANN to the Training set | |
classifier.fit(X_train, y_train, batch_size = 10, epochs = 100) |
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
# Predicting the Test set results | |
y_pred = classifier.predict(X_test) | |
y_pred = (y_pred > 0.5) | |
# Making the Confusion Matrix | |
from sklearn.metrics import confusion_matrix | |
cm = confusion_matrix(y_test, y_pred) |
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 |
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
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
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:]) |