Commit bacedd96 authored by Ashen Udayanga Sudugala's avatar Ashen Udayanga Sudugala

Merge branch 'Navindu' into 'master'

Navindu

See merge request !7
parents a3d1ac21 a4192197
This diff is collapsed.
# -*- 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
# -*- coding: utf-8 -*-
"""
Created on Sat May 16 17:40:32 2020
@author: navin
"""
# Simple Linear Regression
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('dataset_7.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 84].values
# Splitting 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 = 1/3, random_state = 0)
# Training the Simple Linear Regression model on the Training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# Predicting the Test set results
y_pred = regressor.predict(X_test)
# Visualising the Training set results
plt.scatter(X_train, y_train, color = 'red')
plt.plot(X_train, regressor.predict(X_train), color = 'blue')
plt.title('Slowloris Attack Testing')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
# Visualising the Test set results
plt.scatter(X_test, y_test, color = 'red')
plt.plot(X_train, regressor.predict(X_train), color = 'blue')
plt.title('Slowloris Attack Testing')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
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