<jupyter_start><jupyter_text>LSTM<jupyter_code>import numpy as np
import pandas as pd
import deploy_functions as dpf
import helper_functions as hf

import keras
from keras.models import load_model

import warnings
warnings.filterwarnings('ignore')<jupyter_output>Using TensorFlow backend.<jupyter_text>Load Data<jupyter_code>cow_1 = pd.read_json('input/cowrie.json.2017_7_4', lines=True)
cow_2 = pd.read_json('input/cowrie.json.2017_7_6', lines=True)
cow_3 = pd.read_json('input/cowrie.json.2017_7_7', lines=True)
cow = pd.concat([cow_1, cow_2, cow_3], axis=0)
cow.head()<jupyter_output><empty_output><jupyter_text>Process data<jupyter_code>seq = dpf.proc_data(cow)
print (seq[0])<jupyter_output><empty_output><jupyter_text>Load Model<jupyter_code>mod = load_model('lstm/lstm_model.h5') 
mod.summary()<jupyter_output>_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm_11 (LSTM)               (None, 1, 100)            80400     
_________________________________________________________________
lstm_12 (LSTM)               (None, 10)                4440      
=================================================================
Total params: 84,840
Trainable params: 84,840
Non-trainable params: 0
_________________________________________________________________<jupyter_text>Prediction<jupyter_code>d = seq[3]
         
corr = 0
total = 0
pred = []
pred.append(16)

for i in range(1, len(d)):
    temp = d[:i]
    s = [j+1 for j in temp]
    
    if len(s)> 100:
        s = s[len(s)-100:]
    if len(temp) < 100:
        while len(s) is not 100:
            s = [0] + s            
    
    nxt = mod.predict(np.array(s).reshape(1, 1, 100))*18     
    nxt = [round(j-1) for j in nxt[0]]
    
    pred.append(int(nxt[0]))
    if nxt[0] == d[i]:
        corr += 1
    total += 1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17593064762876084, 'fraction_numerical': 0.04589495155532891, 'mean_word_length': 3.917293233082707, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '341234', 'license': 'MIT', 'n_tokens_mistral': 709, 'n_tokens_neox': 654, 'n_words': 129, 'path': 'codes/ml/deploy_lstm.ipynb', 'repo_name': 'soham97/Predictive-Threat-Intelligence', 'size': '1961'}