├── model.h5 ├── reports ├── report.pdf ├── MidReport.pdf ├── presentation.pdf └── MidPresentation.pdf ├── results ├── AccTest.png ├── AccTrain.png ├── GyroTest.png ├── GyroTrain.png ├── UserPlotAcc.png ├── UserPlotGyro.png ├── NN_5_10_20_acc.png ├── NN_5_10_20_gyro.png ├── Acc neuron change.png ├── Gyro neuron change.png ├── Batch_Size variation.png ├── Merged neuron change.png ├── NN_5,5_10,10_20,20_acc.png ├── NN_5,5_10,10_20,20_gyro.png ├── NN_5,5,5_7,7,7_10,10,10_acc.png ├── NN_5,5,5_7,7,7_10,10,10_gyro.png ├── NN_5,5,5_10,10,10_15,15,15_acc.png ├── NN_5,5,5_10,10,10_15,15,15_gyro.png ├── NN_5,5,5_7,7,7_10,10,10_acc_early_stopping.png ├── NN_5,5,5_7,7,7_10,10,10_gyro_early_stopping.png ├── Compile.txt ├── plot.py ├── NN_5,5,5_7,7,7_10,10,10_acc.txt ├── NN_5,5,5_7,7,7_10,10,10_gyro_earlyStopping.txt ├── NN_5_10_20_acc.txt ├── NN_5_10_20_gyro.txt ├── NN_5,5,5_7,7,7_10,10,10_gyro.txt ├── NN_5,5_10,10_20,20_acc.txt ├── NN_5,5_10,10_20,20_gyro.txt ├── NN_5,5,5_10,10,10_15,15,15_gyro.txt ├── NN_5,5,5_10,10,10_15,15,15_acc.txt └── NN_5,5,5_7,7,7_10,10,10_acc_earlyStopping.txt ├── data management code ├── merge.py ├── merge2.0.py ├── compress_file.py └── compress2.0.py ├── plot.py ├── trainingPreprocessedData.py ├── README.md ├── main_RNN.py ├── main.py └── main_NN.py /model.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/model.h5 -------------------------------------------------------------------------------- /reports/report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/reports/report.pdf -------------------------------------------------------------------------------- /results/AccTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/AccTest.png -------------------------------------------------------------------------------- /results/AccTrain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/AccTrain.png -------------------------------------------------------------------------------- /results/GyroTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/GyroTest.png -------------------------------------------------------------------------------- /reports/MidReport.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/reports/MidReport.pdf -------------------------------------------------------------------------------- /results/GyroTrain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/GyroTrain.png -------------------------------------------------------------------------------- /reports/presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/reports/presentation.pdf -------------------------------------------------------------------------------- /results/UserPlotAcc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/UserPlotAcc.png -------------------------------------------------------------------------------- /results/UserPlotGyro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/UserPlotGyro.png -------------------------------------------------------------------------------- /reports/MidPresentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/reports/MidPresentation.pdf -------------------------------------------------------------------------------- /results/NN_5_10_20_acc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5_10_20_acc.png -------------------------------------------------------------------------------- /results/NN_5_10_20_gyro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5_10_20_gyro.png -------------------------------------------------------------------------------- /results/Acc neuron change.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/Acc neuron change.png -------------------------------------------------------------------------------- /results/Gyro neuron change.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/Gyro neuron change.png -------------------------------------------------------------------------------- /results/Batch_Size variation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/Batch_Size variation.png -------------------------------------------------------------------------------- /results/Merged neuron change.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/Merged neuron change.png -------------------------------------------------------------------------------- /results/NN_5,5_10,10_20,20_acc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5_10,10_20,20_acc.png -------------------------------------------------------------------------------- /results/NN_5,5_10,10_20,20_gyro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5_10,10_20,20_gyro.png -------------------------------------------------------------------------------- /results/NN_5,5,5_7,7,7_10,10,10_acc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5,5_7,7,7_10,10,10_acc.png -------------------------------------------------------------------------------- /results/NN_5,5,5_7,7,7_10,10,10_gyro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5,5_7,7,7_10,10,10_gyro.png -------------------------------------------------------------------------------- /results/NN_5,5,5_10,10,10_15,15,15_acc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5,5_10,10,10_15,15,15_acc.png -------------------------------------------------------------------------------- /results/NN_5,5,5_10,10,10_15,15,15_gyro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5,5_10,10,10_15,15,15_gyro.png -------------------------------------------------------------------------------- /results/NN_5,5,5_7,7,7_10,10,10_acc_early_stopping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5,5_7,7,7_10,10,10_acc_early_stopping.png -------------------------------------------------------------------------------- /results/NN_5,5,5_7,7,7_10,10,10_gyro_early_stopping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/Human-Activity-Recognition/master/results/NN_5,5,5_7,7,7_10,10,10_gyro_early_stopping.png -------------------------------------------------------------------------------- /results/Compile.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 2 | 5 3 | 10 4 | 15 5 | 6 | Gyro train 7 | 8 | 1 2 3 9 | 5 10 | 10 11 | 15 12 | 13 | Gyro test 14 | 15 | 1 2 3 16 | 5 17 | 10 18 | 15 19 | 20 | Acc train 21 | 22 | 1 2 3 23 | 5 24 | 10 25 | 15 -------------------------------------------------------------------------------- /data management code/merge.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import os 3 | 4 | file_dir = os.path.dirname(__file__) 5 | 6 | file_path2 = os.path.join(file_dir,'adata.csv') 7 | 8 | with open(file_path2,'w') as file: 9 | csv_file = csv.writer(file) 10 | head = ['index','x','y','z','Activity'] 11 | csv_file.writerow(head) 12 | for i in range(1,14): 13 | print(i) 14 | file_path= os.path.join(file_dir,'pa'+str(i)+'.csv') 15 | with open(file_path) as f: 16 | read = csv.reader(f) 17 | data = list(read) 18 | for j in range(0,len(data)): 19 | csv_file.writerow(data[j]) 20 | -------------------------------------------------------------------------------- /data management code/merge2.0.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import os 3 | 4 | file_dir = os.path.dirname(__file__) 5 | 6 | file_path2 = os.path.join(file_dir,'data.csv') 7 | 8 | with open(file_path2,'w') as file: 9 | csv_file = csv.writer(file) 10 | head = ['index','ax','ay','az','gx','gy','gz','Activity'] 11 | csv_file.writerow(head) 12 | for i in range(1,9): 13 | print(i) 14 | file_path= os.path.join(file_dir,'p'+str(i)+'.csv') 15 | with open(file_path) as f: 16 | read = csv.reader(f) 17 | data = list(read) 18 | for j in range(0,len(data)): 19 | csv_file.writerow(data[j]) 20 | -------------------------------------------------------------------------------- /data management code/compress_file.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import os 3 | 4 | file_dir = os.path.dirname(__file__) 5 | 6 | User_dict = {'a': -0.4,'b': -0.3,'c': -0.2, 7 | 'd': -0.1,'e': 0.1,'f': 0.2, 8 | 'g': 0.3,'h': 0.4,'i': 0} 9 | 10 | Activity_dict = {'stand':1,'sit':2,'walk':3, 11 | 'stairsup':4,'stairsdown':5,'bike':6} 12 | 13 | Model_dict = {'nexus4':1, "s3":2, "s3mini":3, "samsungold":4 } 14 | 15 | for i in range(1,14): 16 | print(i) 17 | file_path= os.path.join(file_dir,'data/pa'+str(i)+'.csv') 18 | file_path2 = os.path.join(file_dir,'Compressed_data/pa'+str(i)+'.csv') 19 | with open(file_path) as f: 20 | read = csv.reader(f) 21 | data = list(read) 22 | 23 | with open(file_path2,'w') as file: 24 | csv_file = csv.writer(file) 25 | #head = ['index','x','y','z','User','Model','Activity'] 26 | #csv_file.writerow(head) 27 | j=0 28 | for i in range(0,len(data)): 29 | if(i%10 == 1): 30 | data_item = [j] 31 | '''sumx=0 32 | sumy=0 33 | sumz=0 34 | for k in range(0,10): 35 | if(i+k < len(data)): 36 | sumx += float(data[i+k][3]) 37 | sumy += float(data[i+k][4]) 38 | sumz += float(data[i+k][5])''' 39 | data_item.append(data[i][3]) 40 | data_item.append(data[i][4]) 41 | data_item.append(data[i][5]) 42 | if(data[i][9] != "null"): 43 | #data_item.append(User_dict[data[i][6]]) 44 | #data_item.append(Model_dict[data[i][7]]) 45 | data_item.append(Activity_dict[data[i][9]]) 46 | csv_file.writerow(data_item) 47 | j+=1 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | figGT = plt.figure() 4 | 5 | plt.plot([5,10,15],[0.4,0.47,0.48]) 6 | plt.plot([5,10,15],[0.45,0.53,0.53]) 7 | plt.plot([5,10,15],[0.42,0.53,0.56]) 8 | 9 | figGT.suptitle('Gyroscope Train Score') 10 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='upper left') 11 | plt.xlabel('Hidden units') 12 | plt.ylabel('F1 score') 13 | 14 | figGT.savefig('GyroTrain.png') 15 | 16 | figGC = plt.figure() 17 | 18 | plt.plot([5,10,15],[0.32,0.42,0.41]) 19 | plt.plot([5,10,15],[0.37,0.46,0.44]) 20 | plt.plot([5,10,15],[0.35,0.33,0.38]) 21 | 22 | figGC.suptitle('Gyroscope Cross Validation Score') 23 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='upper left') 24 | plt.xlabel('Hidden units') 25 | plt.ylabel('F1 score') 26 | 27 | figGC.savefig('GyroTest.png') 28 | 29 | figAT = plt.figure() 30 | 31 | plt.plot([5,10,15],[0.53,0.58,0.59]) 32 | plt.plot([5,10,15],[0.55,0.61,0.62]) 33 | plt.plot([5,10,15],[0.57,0.64,0.66]) 34 | 35 | figAT.suptitle('Accelerometer Train Score') 36 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='upper left') 37 | plt.xlabel('Hidden units') 38 | plt.ylabel('F1 score') 39 | 40 | figAT.savefig('AccTrain.png') 41 | 42 | figAC = plt.figure() 43 | 44 | plt.plot([5,10,15],[0.4,0.4,0.38]) 45 | plt.plot([5,10,15],[0.18,0.36,0.4]) 46 | plt.plot([5,10,15],[0.44,0.4,0.43]) 47 | 48 | figAC.suptitle('Accelerometer Cross Validation Score') 49 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='lower right') 50 | plt.xlabel('Hidden units') 51 | plt.ylabel('F1 score') 52 | 53 | figAC.savefig('AccTest.png') 54 | -------------------------------------------------------------------------------- /results/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | figGT = plt.figure() 4 | 5 | plt.plot([5,10,15],[0.4,0.47,0.48]) 6 | plt.plot([5,10,15],[0.45,0.53,0.53]) 7 | plt.plot([5,10,15],[0.42,0.53,0.56]) 8 | 9 | figGT.suptitle('Gyroscope Train Score') 10 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='upper left') 11 | plt.xlabel('Hidden units') 12 | plt.ylabel('F1 score') 13 | 14 | figGT.savefig('GyroTrain.png') 15 | 16 | figGC = plt.figure() 17 | 18 | plt.plot([5,10,15],[0.32,0.42,0.41]) 19 | plt.plot([5,10,15],[0.37,0.46,0.44]) 20 | plt.plot([5,10,15],[0.35,0.33,0.38]) 21 | 22 | figGC.suptitle('Gyroscope Cross Validation Score') 23 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='upper left') 24 | plt.xlabel('Hidden units') 25 | plt.ylabel('F1 score') 26 | 27 | figGC.savefig('GyroTest.png') 28 | 29 | figAT = plt.figure() 30 | 31 | plt.plot([5,10,15],[0.53,0.58,0.59]) 32 | plt.plot([5,10,15],[0.55,0.61,0.62]) 33 | plt.plot([5,10,15],[0.57,0.64,0.66]) 34 | 35 | figAT.suptitle('Accelerometer Train Score') 36 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='upper left') 37 | plt.xlabel('Hidden units') 38 | plt.ylabel('F1 score') 39 | 40 | figAT.savefig('AccTrain.png') 41 | 42 | figAC = plt.figure() 43 | 44 | plt.plot([5,10,15],[0.4,0.4,0.38]) 45 | plt.plot([5,10,15],[0.18,0.36,0.4]) 46 | plt.plot([5,10,15],[0.44,0.4,0.43]) 47 | 48 | figAC.suptitle('Accelerometer Cross Validation Score') 49 | plt.legend(['Hidden Layer = 1','Hidden Layer = 2','Hidden Layer = 3'],loc='lower right') 50 | plt.xlabel('Hidden units') 51 | plt.ylabel('F1 score') 52 | 53 | figAC.savefig('AccTest.png') 54 | -------------------------------------------------------------------------------- /trainingPreprocessedData.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | import pandas as pd 4 | from numpy import genfromtxt 5 | from sklearn.neural_network import MLPClassifier 6 | from sklearn.metrics import classification_report,f1_score 7 | from sklearn.model_selection import train_test_split 8 | from sklearn import svm 9 | import matplotlib.pyplot as plt 10 | 11 | 12 | X_train = genfromtxt("X_train.txt", delimiter =' ') 13 | X_test = genfromtxt("X_test.txt", delimiter =' ') 14 | y_test = genfromtxt("y_test.txt", delimiter ='\n') 15 | y_train = genfromtxt("y_train.txt", delimiter ='\n') 16 | 17 | y_train = np.array(y_train) 18 | y_test = np.array(y_test) 19 | 20 | print(X_train.shape) 21 | print(y_train.shape) 22 | 23 | def NeuralNetworkTrain(X_train,y_train,X_test,y_test): 24 | train_scores = np.empty(0) 25 | test_scores = np.empty(0) 26 | indices = np.empty(0) 27 | for i in 1,15: 28 | print("hidden layer: ",i,"\n") 29 | mlp = MLPClassifier(hidden_layer_sizes=(i, i, i)) 30 | mlp.fit(X_train,y_train) 31 | 32 | predictions_train = mlp.predict(X_train) 33 | print("Fitting of train data for size ",i," : \n",classification_report(y_train,predictions_train)) 34 | 35 | predictions_test = mlp.predict(X_test) 36 | print("Fitting of test data for size ",i," : \n",classification_report(y_test,predictions_test)) 37 | 38 | train_scores = np.append(train_scores, f1_score(y_train,predictions_train,average='macro')) 39 | test_scores = np.append(test_scores, f1_score(y_test,predictions_test,average='macro')) 40 | indices = np.append(indices,i) 41 | 42 | 43 | plt.plot(indices, train_scores) 44 | plt.plot(indices,test_scores) 45 | 46 | plt.legend(['Train scores','Test scores'],loc='upper left') 47 | plt.show() 48 | 49 | 50 | NeuralNetworkTrain(X_train,y_train,X_test,y_test) -------------------------------------------------------------------------------- /data management code/compress2.0.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import os 3 | 4 | file_dir = os.path.dirname(__file__) 5 | 6 | Activity_dict = {'stand':1,'sit':2,'walk':3, 7 | 'stairsup':4,'stairsdown':5,'bike':6} 8 | 9 | 10 | for i in range(1,9): 11 | print(i) 12 | file_patha = os.path.join(file_dir,'data/pa'+str(i)+'.csv') 13 | file_pathg = os.path.join(file_dir,'data/pg'+str(i)+'.csv') 14 | file_path = os.path.join(file_dir,'Compressed_data/p'+str(i)+'.csv') 15 | 16 | with open(file_patha) as fa: 17 | reada = csv.reader(fa) 18 | dataa = list(reada) 19 | 20 | with open(file_pathg) as fg: 21 | readg = csv.reader(fg) 22 | datag = list(readg) 23 | 24 | with open(file_path,'w') as file: 25 | csv_file = csv.writer(file) 26 | countera,counterg,l = 0,0,min(len(datag), len(dataa)) 27 | while(countera < l and counterg < l): 28 | if(countera%100000 < 10 ): 29 | print(countera) 30 | if(dataa[countera][0] == datag[counterg][0]): 31 | data_item = [countera] 32 | data_item.append(dataa[i][3]) 33 | data_item.append(dataa[i][4]) 34 | data_item.append(dataa[i][5]) 35 | data_item.append(datag[i][3]) 36 | data_item.append(datag[i][4]) 37 | data_item.append(datag[i][5]) 38 | if(dataa[countera][9] != "null" and datag[counterg][9] != "null"): 39 | data_item.append(Activity_dict[dataa[i][9]]) 40 | csv_file.writerow(data_item) 41 | countera+=10 42 | counterg+=10 43 | countera+=1 44 | counterg+=1 45 | else: 46 | if(int(dataa[countera][0])<10 and int(datag[counterg][0])>=10): 47 | counterg = counterg + 10 48 | elif(int(datag[counterg][0])<10 and int(dataa[countera][0])>=10): 49 | countera = countera + 10 50 | elif(int(datag[counterg][0])