Skip to content

Instantly share code, notes, and snippets.

View sagarhowal's full-sized avatar
💭
commit-ment issues

Sagar Howal sagarhowal

💭
commit-ment issues
  • Dublin, Ireland
View GitHub Profile
@sagarhowal
sagarhowal / LabelEncoder.py
Last active December 25, 2017 10:43
Encoding Categorical Data
#Encoding Categorical Data
from sklearn.preprocessing import LabelEncoder
labelencoder = LabelEncoder()
y = labelencoder.fit_transform(y)
@sagarhowal
sagarhowal / import_keras.py
Created December 25, 2017 10:45
Importing the Keras libraries and packages
# Importing the Keras libraries and packages
import keras
from keras.models import Sequential
from keras.layers import Dense
@sagarhowal
sagarhowal / init_sequential.py
Created December 25, 2017 10:46
Initialising the ANN
# Initialising the ANN
classifier = Sequential()
@sagarhowal
sagarhowal / create_ANN_keras.py
Created December 25, 2017 10:47
ANN Design and Compiling
# 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
@sagarhowal
sagarhowal / ann_fitting.py
Created December 25, 2017 10:48
Fitting an ANN
# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)
@sagarhowal
sagarhowal / keras_predict_ann.py
Created December 25, 2017 10:49
Predicting the Test set results and Confusion Matrix in Keras
# 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)
#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
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
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]
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:])