Exemple #1
0
# ==========================================================================================
# Fetching data for trainig the model
print("Reading the data from the files...\n\n")
train_path = "./raw/train/"
data = obj.read_data(train_path)
print("Preprocessing the data loaded...\n\n")
data, le = obj.preprocess_data(data)

# Function for splitting the data in the train and the test set for a particular class
# We are keeping the data for 17 people in the train set and rest in the test set
train_data = data[data["id"] < 1616]
test_data = data[data["id"] > 1615]

# Splitting the data in segments
print("Splitting the train data into segments for training...\n\n")
x_train, y_train = obj.segments(train_data, TIME_PERIODS, STEP_DISTANCE,
                                'label')
print("Splitting the train data into segments for training...\n\n")
x_test, y_test = obj.segments(test_data, TIME_PERIODS, STEP_DISTANCE, 'label')

# Creating the variables for training the model
num_time_periods, sensors = x_train.shape[1], x_train.shape[2]
num_classes = le.classes_.size

# We need to optimize the shape of the input data so that it can be fed to the neural network
input_shape = (num_time_periods, sensors)
# x_train = x_train.reshape(x_train.shape[0], input_shape)
# x_test = x_test.reshape(x_test.shape[0], input_shape)

# Converting the datatypes as accepted by keras
x_train = x_train.astype('float32')
y_train = y_train.astype('float32')