text_html_output_1.png
from sklearn import preprocessing

from sklearn.preprocessing import OneHotEncoder

import pandas as pd

X_train = df_train.drop('xAttack', axis=1)
Y_train = df_train.loc[:, ['xAttack']]
X_test = df_test.drop('xAttack', axis=1)
Y_test = df_test.loc[:, ['xAttack']]

le = preprocessing.LabelEncoder()
enc = OneHotEncoder()
lb = preprocessing.LabelBinarizer()

X_train['protocol_type'] = le.fit_transform(X_train['protocol_type'])
X_test['protocol_type'] = le.fit_transform(X_test['protocol_type'])

Y_train['xAttack'] = le.fit_transform(Y_train['xAttack'])
lb.fit_transform(Y_train['xAttack'])
Y_test['xAttack'] = le.fit_transform(Y_test['xAttack'])
lb.fit_transform(Y_test['xAttack'])

con_list = ['protocol_type', 'service', 'flag', 'land', 'logged_in', 'su_attempted', 'is_host_login', 'is_guest_login']
con_train = X_train.drop(con_list, axis=1)
stdtrain = con_train.std(axis=0)
std_X_train = stdtrain.to_frame()

X_train = X_train.drop(['num_outbound_cmds'], axis=1)
X_test = X_test.drop(['num_outbound_cmds'], axis=1)
df_train = pd.concat([X_train, Y_train], axis=1)

stdrop_list = ['urgent', 'num_shells', 'root_shell', 'num_failed_logins', 'num_access_files', 'dst_host_srv_diff_host_rate', 'diff_srv_rate', 'dst_host_diff_srv_rate', 'wrong_fragment']
X_test_stdrop = X_test.drop(stdrop_list, axis=1)
X_train_stdrop = X_train.drop(stdrop_list, axis=1)
df_train_stdrop = pd.concat([X_train_stdrop, Y_train], axis=1)
df_train_stdrop.head()