Commit dda254f5 authored by Navindu Eshan's avatar Navindu Eshan

Delete slowlorisModel.py

parent e8055075
# -*- coding: utf-8 -*-
"""Navindu.ipynb"""
# Importing the libraries
# Fundamental package for scientific computing
import numpy as np
# Plotting library
import matplotlib.pyplot as plt
# Data manipulation and analysis library
import pandas as pd
# Completing missing values
from sklearn.impute import SimpleImputer
# Encode target labels with value between 0 and n_classes-1
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
# Applies transformers to columns of an array or pandas DataFrame
from sklearn.compose import ColumnTransformer
# Split arrays or matrices into random train and test subsets
from sklearn.model_selection import train_test_split
# Standardize features by removing the mean and scaling to unit variance
from sklearn.preprocessing import StandardScaler
# Logistic Regression classifier
from sklearn.linear_model import LogisticRegression
# Compute confusion matrix to evaluate the accuracy of a classification
from sklearn.metrics import confusion_matrix
# Accuracy classification score
from sklearn.metrics import accuracy_score
# Build a text report showing the main classification metrics
from sklearn.metrics import classification_report
# Data visualization library based on matplotlib
import seaborn as sns
# Importing the dataset
dataset = pd.read_csv('/Users/harithachanuka/Documents/SLIIT/Research/Harry/Wanheda_Server/Slowloris/SlowlorisDATASET.numbers')
# Read in data and display first 5 rows
dataset.head()
# Drop the dataset
dataset = dataset.dropna()
#Data cleaning
dataset.isnull().sum()
#Encoding categarical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_Y = LabelEncoder()
dataset.iloc[:, 78] = labelencoder_Y.fit_transform(dataset.iloc[:, 78])
dataset.shape
dataset = dataset[~dataset.isin([np.isnan]).any(1)].astype(np.float64)
dataset = dataset[~dataset.isin([np.isinf]).any(1)].astype(np.float64)
dataset = dataset.mask(np.isinf(dataset))
dataset = dataset.dropna()
dataset.shape
#returns a boolean array of the X
np.any(np.isinf(dataset))
#detect numpy arrays of different data types
np.any(np.isnan(dataset))
#get all colomns without last colomn in X axis and get last colomn in y axis
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 78].values
dataset.info()
y
df = pd.DataFrame(data=X)
df
#Spliting the dataset into the training set and test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
#feature scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)
y_train.shape
#fitting simple linear regression to the training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
#predecting the data
y_pred = regressor.predict(X_test)
print(y_pred)
X_train.shape
y_train.shape
#visual plot
plt.scatter(X_train, y_train, color = 'red')
plt.plot(X_train, y_train, color = 'red')
plt.plot(X_test, y_pred, color = 'blue')
plt.title('Slowloris Attack')
plt.xlabel('Flow Duration')
plt.ylabel('Total Length')
plt.show()
\ No newline at end of file
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