# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + colab={} colab_type="code" id="O4AYTFpvBG3Y"
# #!/usr/bin/env python

# + colab={"base_uri": "https://localhost:8080/", "height": 89} colab_type="code" id="d68KJ-lSBXr8" outputId="5440b856-5f77-4495-da10-c18c2d0acabb"
#Import Liabraries
import numpy as np
import pandas as pd
import csv
import matplotlib.pyplot as plt
import seaborn as sns;
import pandas.util.testing as tm
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, StandardScaler
from keras.utils import plot_model
from keras.models import Sequential, load_model
from keras.models import Sequential
from keras.layers import Dense
from keras.utils import np_utils

# + colab={"base_uri": "https://localhost:8080/", "height": 333} colab_type="code" id="lXiZ4s1-BlSQ" outputId="5872c08d-f21c-4eac-99f5-9a7696863f3f"
data_attack = pd.read_csv('dataset_attack.csv')
data_normal = pd.read_csv('dataset_normal.csv')
# data_normal.head()
# -

data_normal.columns=[ 'frame.len', 'frame.protocols', 'ip.hdr_len',
       'ip.len', 'ip.flags.rb', 'ip.flags.df', 'p.flags.mf', 'ip.frag_offset',
       'ip.ttl', 'ip.proto', 'ip.src', 'ip.dst', 'tcp.srcport', 'tcp.dstport',
       'tcp.len', 'tcp.ack', 'tcp.flags.res', 'tcp.flags.ns', 'tcp.flags.cwr',
       'tcp.flags.ecn', 'tcp.flags.urg', 'tcp.flags.ack', 'tcp.flags.push',
       'tcp.flags.reset', 'tcp.flags.syn', 'tcp.flags.fin', 'tcp.window_size',
       'tcp.time_delta','class']
data_attack.columns=[ 'frame.len', 'frame.protocols', 'ip.hdr_len',
       'ip.len', 'ip.flags.rb', 'ip.flags.df', 'p.flags.mf', 'ip.frag_offset',
       'ip.ttl', 'ip.proto', 'ip.src', 'ip.dst', 'tcp.srcport', 'tcp.dstport',
       'tcp.len', 'tcp.ack', 'tcp.flags.res', 'tcp.flags.ns', 'tcp.flags.cwr',
       'tcp.flags.ecn', 'tcp.flags.urg', 'tcp.flags.ack', 'tcp.flags.push',
       'tcp.flags.reset', 'tcp.flags.syn', 'tcp.flags.fin', 'tcp.window_size',
       'tcp.time_delta','class']

data_normal.to_csv (r'dataset_normal_cleaned.csv', index=False, header=True)
data_attack.to_csv (r'dataset_attack_cleaned.csv', index=False, header=True)

# + colab={} colab_type="code" id="nV46tkd5v8z4"
data_normal = pd.read_csv('dataset_normal_cleaned.csv')
data_normal.head()
# -

data_attack = pd.read_csv('dataset_attack_cleaned.csv')
data_attack.head()

data_normal=data_normal.drop(['ip.src', 'ip.dst','frame.protocols'],axis=1)
data_attack=data_attack.drop(['ip.src', 'ip.dst','frame.protocols'],axis=1)

features = data_attack.head(0)
features=data_attack.columns.tolist()
print(features)

X_normal= data_normal[features].values
X_attack= data_attack[features].values
Y_normal= data_normal['class']
Y_attack= data_attack['class']
X=np.concatenate((X_normal,X_attack))
Y=np.concatenate((Y_normal,Y_attack))





StarcoderdataJupyterScriptsDedupFiltered