<jupyter_start><jupyter_text>Model 1 : Simple RNN<jupyter_code>rnn_model = Sequential()
rnn_model.add(Embedding(num_words, 32, input_length=max_log_length))
rnn_model.add(SimpleRNN(units=32, activation='relu'))
rnn_model.add(Dense(units=1, activation = 'sigmoid'))
rnn_model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy', f1_m, precision_m, recall_m])
rnn_model.summary()
rnn_model.fit(x=X_train, y=y_train, epochs=3, batch_size = 128, validation_split=0.25)
loss, accuracy, f1_score, precision, recall = rnn_model.evaluate(x=X_test, y=y_test, batch_size = 128)
print("loss : ", loss)
print("acc : ", accuracy)
print("f1_score : ", f1_score)
print("precision : ", precision)
print("recall : ", recall)
table["model 1"]["loss"] = loss
table["model 1"]["accuracy"] = accuracy
table["model 1"]["f1"] = f1_score
table["model 1"]["precision"] = precision
table["model 1"]["recall"] = recall<jupyter_output><empty_output><jupyter_text>Model 2 : LSTM + Dropout Layers<jupyter_code>lstm_model = Sequential()
lstm_model.add(Embedding(num_words, 32, input_length=max_log_length))
lstm_model.add(LSTM(units=64, recurrent_dropout=0.5))
lstm_model.add(Dropout(0.5))
lstm_model.add(Dense(units=1, activation = 'relu'))
lstm_model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy', f1_m, precision_m, recall_m])
lstm_model.summary()
lstm_model.fit(x=X_train, y=y_train, epochs=3, batch_size = 128, validation_split=0.25)
loss2, accuracy2, f1_score2, precision2, recall2 = lstm_model.evaluate(x=X_test, y=y_test, batch_size = 128)
print("loss : ", loss2)
print("acc : ", accuracy2)
print("f1_score : ", f1_score2)
print("precision : ", precision2)
print("recall : ", recall2)
table["model 2"]["loss"] = loss2
table["model 2"]["accuracy"] = accuracy2
table["model 2"]["f1"] = f1_score2
table["model 2"]["precision"] = precision2
table["model 2"]["recall"] = recall2<jupyter_output><empty_output><jupyter_text>Model 3 : LSTM + Dropout Layers<jupyter_code>my_model = Sequential()
my_model.add(Embedding(num_words, 32, input_length=max_log_length))
my_model.add(Dense(units=32, activation = 'relu'))
my_model.add(LSTM(units=64, recurrent_dropout=0.33))
my_model.add(Dropout(0.25)) # f1, recall, and precision = 0 when dropout too high
my_model.add(Dense(units=1, activation = 'relu'))
my_model.compile(loss = 'binary_crossentropy', optimizer = 'sgd', metrics = ['accuracy', 'mae', f1_m, precision_m, recall_m])
my_model.summary()
my_model.fit(x=X_train, y=y_train, epochs=3, batch_size = 128, validation_split=0.25)
loss3, mae1, accuracy3, f1_score3, precision3, recall3 = my_model.evaluate(x=X_test, y=y_test, batch_size = 128)
print("loss : ", loss3)
print("mae : ", mae1)
print("acc : ", accuracy3)
print("f1_score : ", f1_score3)
print("precision : ", precision3)
print("recall : ", recall3)
table["model 3"]["loss"] = loss3
table["model 3"]["mae"] = mae1
table["model 3"]["accuracy"] = accuracy3
table["model 3"]["f1"] = f1_score3
table["model 3"]["precision"] = precision3
table["model 3"]["recall"] = recall3
pd.options.display.max_rows=None
pd.options.display.float_format = "{:,.3f}".format
#### summary
pd.DataFrame(table).transpose()<jupyter_output><empty_output><jupyter_text>Submitting Best Model<jupyter_code>to_csv("submission.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17306538692261547, 'fraction_numerical': 0.038992201559688064, 'mean_word_length': 8.751461988304094, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '522336', 'license': 'MIT', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1283, 'n_words': 218, 'path': 'Fall2020/MSDS422/rnn/TwitterChallengeAsn7.ipynb', 'repo_name': 'kbridge14/regression_things', 'size': '3334'}