text_plain_output_1.png
from sklearn.ensemble import RandomForestRegressor

from sklearn.metrics import mean_absolute_error

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

test_data = pd.read_csv('../input/testdata/UNSW_NB15_testing-set.csv', index_col=0)
train_data = pd.read_csv('../input/testdata/UNSW_NB15_training-set.csv', index_col=0)
test_data.index = test_data.index + len(train_data)
(len(train_data), len(test_data))
total = pd.concat([train_data, test_data], axis=0)
significant_proto = total.proto.value_counts()[:5]
total.loc[~total['proto'].isin(significant_proto.index), 'proto'] = '-'
total = pd.concat([total, pd.get_dummies(total['proto'], prefix='proto')], axis=1)
total.drop('proto', axis=1, inplace=True)
features = ['dur', 'proto_-', 'proto_arp', 'proto_ospf', 'proto_tcp', 'proto_udp', 'proto_unas', 'spkts', 'dpkts', 'sbytes', 'rate']
values = ['dur', 'spkts', 'dpkts', 'rate', 'sbytes']
total['dur'] = np.log(total['dur'] + 1)
total['spkts'] = np.log(total['spkts'] + 1)
total['dpkts'] = np.log(total['dpkts'] + 1)
total['rate'] = np.log(total['rate'] + 1)
total['sbytes'] = np.log(total['sbytes'] + 1)
train_data = total.loc[train_data.index]
test_data = total.loc[test_data.index]

X = train_data[features]
y = train_data['label']
y.count
model = RandomForestRegressor()
model.fit(X, y)
predictions = model.predict(test_data[features])
mae = mean_absolute_error(predictions, test_data.label)
print(mae)