cur_features = min_max_scaler.fit_transform(cur_features) cur_feature_name = feature_names[i] ### split data into training set and label set X_train, X_test, y_train, y_test = train_test_split(cur_features, onehotlabels, test_size=0.4, random_state=42) #X_train, X_test, y_train, y_test = train_test_split(features_minmax, labels, test_size=0.4, random_state=42) ### adjust the dataset dimension # reshape X to be [samples, time steps, features] X_train_LSTM = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1])) X_test_LSTM = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1])) ### create the deep learning models epochs = 15 batch_size = 195 #195 best now #190 # 100 # 250 dropoutRate = 0.2 ## stacked LSTM model6, hist6 = deep_learning_models.stacked_LSTM(X_train_LSTM, y_train, X_test_LSTM, y_test, batch_size, epochs) prediction6 = model6.predict(X_test_LSTM) prediction6_re = np.argmax(prediction6, axis=1) stacked_LSTM_precision = deep_learning_models.getAccuracy( prediction6, y_test) print("Precision for stacked LSTM") print(cur_feature_name) print(stacked_LSTM_precision) features_analysis_result[cur_feature_name] = stacked_LSTM_precision
""" y_test_re = np.argmax(y_test, axis=1) accuracies = list() precisions = list() Fs = list() TNRs = list() recalls = list() ### Bidirectional LSTM #start_time0 = time.clock() model0, hist0 = deep_learning_models.Bidirectional_LSTM(X_train_LSTM, y_train, X_test_LSTM, y_test, batch_size, epochs) prediction0 = model0.predict(X_test_LSTM) #end_time0 = time.clock() #Bi_LSTM_performance = end_time0 - start_time0 prediction0_re = np.argmax(prediction0, axis=1) Bidirectional_LSTM_accuracy, bi_precision, bi_recall, bi_TNR, bi_F = deep_learning_models.getAccuracy(prediction0, y_test) keys = hist0.history.keys() print(keys) print("Precision for bidirectional LSTM") print(Bidirectional_LSTM_accuracy) print(bi_precision) print(bi_recall) print(bi_TNR) print(bi_F) accuracy_pair = list() accuracy_pair.append("bidirectional LSTM") accuracy_pair.append(Bidirectional_LSTM_accuracy) accuracies.append(accuracy_pair) #start_time1 = time.clock() model1, hist1 = deep_learning_models.basic_LSTM(X_train_LSTM, y_train, X_test_LSTM, y_test, batch_size, epochs)
""" epochs = 200 batch_size = 20 dropoutRate = 0.3 """ y_test_re = np.argmax(y_test, axis=1) ### Bidirectional LSTM start_time0 = time.clock() model0, hist0 = deep_learning_models.Bidirectional_LSTM( X_train_LSTM, y_train, X_test_LSTM, y_test, batch_size, epochs) prediction0 = model0.predict(X_test_LSTM) end_time0 = time.clock() Bi_LSTM_performance = end_time0 - start_time0 prediction0_re = np.argmax(prediction0, axis=1) Bidirectional_LSTM_accuracy = deep_learning_models.getAccuracy( prediction0, y_test) keys = hist0.history.keys() print(keys) print("Precision for bidirectional LSTM") print(Bidirectional_LSTM_accuracy) """ start_time1 = time.clock() model1, hist1 = deep_learning_models.basic_LSTM(X_train_LSTM, y_train, X_test_LSTM, y_test, batch_size, epochs) prediction1 = model1.predict(X_test_LSTM) end_time1 = time.clock() basic_LSTM_performance = end_time1 - start_time1 prediction1_re = np.argmax(prediction1, axis=1) basic_LSTM_accuracy = deep_learning_models.getAccuracy(prediction1, y_test) keys = hist1.history.keys() print(keys) print("Precision for basic LSTM")