-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUsingModel.py
More file actions
32 lines (25 loc) · 1.14 KB
/
Copy pathUsingModel.py
File metadata and controls
32 lines (25 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding: utf-8
import numpy as np
import pandas as pd
from sklearn import utils
import matplotlib
#Read csv file using pandas
read_data = pd.read_csv('kddcup_data_10_percent_corrected.csv', low_memory=False)
print("Data File read successfully.")
#Read txt files
#df = pd.read_fwf('input.txt')
read_data = read_data[read_data['service'] == "http"]
read_data = read_data[read_data["logged_in"] == 1]
#Out of the 41 available features in the kdd data set, here I am taking only 3 relevant features.
print("Extracting the relevant features from the file.")
applicable_features = [
"duration",
"src_bytes",
"dst_bytes",
"class_label" ]
# replace the read_data with a subset containing only the applicable features to train the model
read_data = read_data[applicable_features]
# normalise the read_data - which leads to better accuracy and reduces numerical instability.
read_data["duration"] = np.log((read_data["duration"] + 0.1).astype(float))
read_data["src_bytes"] = np.log((read_data["src_bytes"] + 0.1).astype(float))
read_data["dst_bytes"] = np.log((read_data["dst_bytes"] + 0.1).astype(float))