Created on Wed Sep 27 14:34:20 2017 This is a small project for CNN in KERAS. This file creates, trains and save a convolutional neural network for Human Acitivity Recognition. The data we used for this file is released and provided by Wireless Sensor Data Mining (WISDM) lab and can be found on this link. http://www.cis.fordham.edu/wisdm/dataset.php Feel free to use this code and site this repositry if you use it for your reports or project. @author: Muhammad Shahnawaz """

importing libraries and dependecies

import pandas as pd import numpy as np import matplotlib.pyplot as plt from scipy import stats from keras.models import Sequential from keras.layers import Dense, Conv2D, MaxPooling2D, Flatten, Dropout #from keras import backend as K from keras import optimizers #K.set_image_dim_ordering('th')

setting up a random seed for reproducibility

random_seed = 611 np.random.seed(random_seed)

matplotlib inline

plt.style.use('ggplot')

defining function for loading the dataset

def readData(filePath): # attributes of the dataset columnNames = ['user_id','activity','timestamp','x-axis','y-axis','z-axis'] data = pd.read_csv(filePath,header = None, names=columnNames,na_values=';') return data

defining a function for feature normalization

(feature - mean)/stdiv

def featureNormalize(dataset): mu = np.mean(dataset,axis=0) sigma = np.std(dataset,axis=0) return (dataset-mu)/sigma

defining the function to plot a single axis data

def plotAxis(axis,x,y,title): axis.plot(x,y) axis.set_title(title) axis.xaxis.set_visible(False) axis.set_ylim([min(y)-np.std(y),max(y)+np.std(y)]) axis.set_xlim([min(x),max(x)]) axis.grid(True)