Commit 748996d1 authored by U C S Bandara's avatar U C S Bandara

Training code

parent 922c1faf
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
#importing dataset
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sn
dataset = pd.read_csv('DrDoS_NTP.csv')
#EDA
dataset.head()
dataset.columns
dataset.head
dataset.describe()
#cleaning
dataset.isna().any()
#encoding
dataset = pd.get_dummies(dataset)
dataset.columns
dataset = dataset.drop(columns = [' Timestamp','Fwd PSH Flags',' Bwd PSH Flags',' Fwd URG Flags',' Bwd URG Flags'])
#remove extra column
attack_id = dataset['Flow ID']
d_port = dataset[' Destination Port']
state = dataset[' Inbound']
dataset = dataset.drop(columns = ['Flow ID',' Destination Port',' Inbound'])
#deviding into traing and testing
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(dataset,state,test_size = 1, random_state = 0)
# feture scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train2 = pd.DataFrame(sc_X.fit_transform(X_train))
X_test2 = pd.DataFrame(sc_X.transform(X_test))
X_train2.columns = X_train.columns.values
X_test2.columns = X_test.columns.values
X_train2.index = X_train.index.values
X_test2.index = X_test.index.values
X_train = X_train2
X_test = X_test2
## SVM (Linear)
from sklearn.svm import SVC
classifier = SVC(random_state = 0, kernel = 'linear')
classifier.fit(X_train,y_train)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment