2017-07-12 10:25:55 +02:00
|
|
|
import json
|
|
|
|
import logging
|
2017-07-09 23:58:08 +02:00
|
|
|
import os
|
2017-07-03 13:48:12 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
import numpy as np
|
2017-07-14 14:58:17 +02:00
|
|
|
import pandas as pd
|
|
|
|
import tensorflow as tf
|
2017-07-11 21:06:58 +02:00
|
|
|
from keras.callbacks import ModelCheckpoint, CSVLogger, EarlyStopping
|
2017-07-08 17:46:07 +02:00
|
|
|
from keras.models import load_model
|
2017-06-30 10:12:20 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
import arguments
|
2017-06-30 10:12:20 +02:00
|
|
|
import dataset
|
2017-07-07 16:48:10 +02:00
|
|
|
import hyperband
|
2017-06-30 10:12:20 +02:00
|
|
|
import models
|
2017-07-12 10:25:55 +02:00
|
|
|
# create logger
|
2017-07-14 14:58:17 +02:00
|
|
|
import visualize
|
|
|
|
from dataset import load_or_generate_h5data
|
2017-07-30 13:47:11 +02:00
|
|
|
from utils import exists_or_make_path, get_custom_class_weights
|
2017-09-01 10:42:26 +02:00
|
|
|
from arguments import get_model_args
|
2017-07-14 14:58:17 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
logger = logging.getLogger('logger')
|
|
|
|
logger.setLevel(logging.DEBUG)
|
2017-07-03 13:48:12 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
# create console handler and set level to debug
|
|
|
|
ch = logging.StreamHandler()
|
|
|
|
ch.setLevel(logging.DEBUG)
|
2017-07-05 21:19:19 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
# create formatter
|
|
|
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
2017-07-05 21:19:19 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
# add formatter to ch
|
|
|
|
ch.setFormatter(formatter)
|
2017-07-03 13:48:12 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
# add ch to logger
|
|
|
|
logger.addHandler(ch)
|
2017-07-05 21:19:19 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
ch = logging.FileHandler("info.log")
|
|
|
|
ch.setLevel(logging.DEBUG)
|
2017-07-07 16:48:10 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
# create formatter
|
|
|
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
2017-07-03 13:48:12 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
# add formatter to ch
|
|
|
|
ch.setFormatter(formatter)
|
2017-07-03 13:48:12 +02:00
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
# add ch to logger
|
|
|
|
logger.addHandler(ch)
|
2017-07-05 17:37:08 +02:00
|
|
|
|
2017-07-14 14:58:17 +02:00
|
|
|
args = arguments.parse()
|
2017-07-05 17:37:08 +02:00
|
|
|
|
2017-07-14 14:58:17 +02:00
|
|
|
if args.gpu:
|
|
|
|
config = tf.ConfigProto(log_device_placement=True)
|
|
|
|
config.gpu_options.per_process_gpu_memory_fraction = 0.5
|
|
|
|
config.gpu_options.allow_growth = True
|
|
|
|
session = tf.Session(config=config)
|
2017-06-30 10:42:21 +02:00
|
|
|
|
2017-07-30 13:47:11 +02:00
|
|
|
# default parameter
|
|
|
|
PARAMS = {
|
|
|
|
"type": args.model_type,
|
2017-09-01 10:42:26 +02:00
|
|
|
"depth": args.model_depth,
|
2017-07-30 13:47:11 +02:00
|
|
|
"batch_size": 64,
|
|
|
|
"window_size": args.window,
|
|
|
|
"domain_length": args.domain_length,
|
|
|
|
"flow_features": 3,
|
|
|
|
#
|
|
|
|
'dropout': 0.5,
|
|
|
|
'domain_features': args.domain_embedding,
|
|
|
|
'embedding_size': args.embedding,
|
|
|
|
'flow_features': 3,
|
|
|
|
'filter_embedding': args.hidden_char_dims,
|
|
|
|
'hidden_embedding': args.domain_embedding,
|
|
|
|
'kernel_embedding': 3,
|
2017-09-05 17:40:57 +02:00
|
|
|
'filter_main': 128,
|
|
|
|
'dense_main': 128,
|
2017-07-30 13:47:11 +02:00
|
|
|
'kernels_main': 3,
|
2017-08-02 12:58:09 +02:00
|
|
|
'input_length': 40,
|
|
|
|
'model_output': args.model_output
|
2017-07-30 13:47:11 +02:00
|
|
|
}
|
|
|
|
|
2017-06-30 10:42:21 +02:00
|
|
|
|
2017-07-08 11:53:03 +02:00
|
|
|
def main_paul_best():
|
2017-07-14 14:58:17 +02:00
|
|
|
pauls_best_params = models.pauls_networks.best_config
|
|
|
|
main_train(pauls_best_params)
|
2017-07-08 11:53:03 +02:00
|
|
|
|
|
|
|
|
2017-07-07 16:48:10 +02:00
|
|
|
def main_hyperband():
|
|
|
|
params = {
|
|
|
|
# static params
|
|
|
|
"type": ["paul"],
|
2017-07-12 10:25:55 +02:00
|
|
|
"batch_size": [args.batch_size],
|
2017-07-07 16:48:10 +02:00
|
|
|
"window_size": [10],
|
|
|
|
"domain_length": [40],
|
|
|
|
"flow_features": [3],
|
|
|
|
"input_length": [40],
|
|
|
|
# model params
|
2017-07-29 19:47:02 +02:00
|
|
|
"embedding_size": [8, 16, 32, 64, 128, 256],
|
|
|
|
"filter_embedding": [8, 16, 32, 64, 128, 256],
|
2017-07-07 16:48:10 +02:00
|
|
|
"kernel_embedding": [1, 3, 5, 7, 9],
|
2017-07-29 19:47:02 +02:00
|
|
|
"hidden_embedding": [8, 16, 32, 64, 128, 256],
|
2017-07-07 16:48:10 +02:00
|
|
|
"dropout": [0.5],
|
2017-07-29 19:47:02 +02:00
|
|
|
"domain_features": [8, 16, 32, 64, 128, 256],
|
|
|
|
"filter_main": [8, 16, 32, 64, 128, 256],
|
2017-07-07 16:48:10 +02:00
|
|
|
"kernels_main": [1, 3, 5, 7, 9],
|
2017-07-29 19:47:02 +02:00
|
|
|
"dense_main": [8, 16, 32, 64, 128, 256],
|
2017-07-07 16:48:10 +02:00
|
|
|
}
|
|
|
|
|
2017-07-12 10:25:55 +02:00
|
|
|
logger.info("create training dataset")
|
2017-09-02 16:02:48 +02:00
|
|
|
domain_tr, flow_tr, name_tr, client_tr, server_tr = load_or_generate_h5data(args.train_h5data, args.train_data,
|
|
|
|
args.domain_length, args.window)
|
2017-07-12 10:25:55 +02:00
|
|
|
hp = hyperband.Hyperband(params,
|
|
|
|
[domain_tr, flow_tr],
|
|
|
|
[client_tr, server_tr])
|
|
|
|
results = hp.run()
|
|
|
|
json.dump(results, open("hyperband.json"))
|
2017-07-07 16:48:10 +02:00
|
|
|
|
|
|
|
|
2017-07-30 14:07:39 +02:00
|
|
|
def main_train(param=None):
|
|
|
|
logger.info(f"Create model path {args.model_path}")
|
2017-07-11 21:06:58 +02:00
|
|
|
exists_or_make_path(args.model_path)
|
2017-07-30 14:07:39 +02:00
|
|
|
logger.info(f"Use command line arguments: {args}")
|
2017-07-11 21:06:58 +02:00
|
|
|
|
2017-09-02 16:02:48 +02:00
|
|
|
domain_tr, flow_tr, name_tr, client_tr, server_windows_tr = load_or_generate_h5data(args.train_h5data,
|
|
|
|
args.train_data,
|
|
|
|
args.domain_length,
|
|
|
|
args.window)
|
2017-06-30 10:12:20 +02:00
|
|
|
|
2017-07-14 14:58:17 +02:00
|
|
|
if not param:
|
2017-07-30 13:47:11 +02:00
|
|
|
param = PARAMS
|
2017-07-30 14:07:39 +02:00
|
|
|
logger.info(f"Generator model with params: {param}")
|
2017-07-30 13:47:11 +02:00
|
|
|
embedding, model, new_model = models.get_models_by_params(param)
|
2017-07-12 10:25:55 +02:00
|
|
|
logger.info("define callbacks")
|
2017-07-14 14:58:17 +02:00
|
|
|
callbacks = []
|
|
|
|
callbacks.append(ModelCheckpoint(filepath=args.clf_model,
|
|
|
|
monitor='val_loss',
|
|
|
|
verbose=False,
|
|
|
|
save_best_only=True))
|
|
|
|
callbacks.append(CSVLogger(args.train_log))
|
2017-07-30 14:07:39 +02:00
|
|
|
logger.info(f"Use early stopping: {args.stop_early}")
|
2017-07-14 14:58:17 +02:00
|
|
|
if args.stop_early:
|
|
|
|
callbacks.append(EarlyStopping(monitor='val_loss',
|
|
|
|
patience=5,
|
|
|
|
verbose=False))
|
|
|
|
custom_metrics = models.get_metric_functions()
|
2017-07-14 15:57:52 +02:00
|
|
|
|
2017-07-30 12:50:26 +02:00
|
|
|
server_tr = np.max(server_windows_tr, axis=1)
|
2017-07-29 19:42:36 +02:00
|
|
|
|
2017-07-14 15:57:52 +02:00
|
|
|
if args.class_weights:
|
|
|
|
logger.info("class weights: compute custom weights")
|
2017-07-30 13:47:11 +02:00
|
|
|
custom_class_weights = get_custom_class_weights(client_tr.value, server_tr)
|
2017-07-14 21:01:08 +02:00
|
|
|
logger.info(custom_class_weights)
|
2017-07-14 15:57:52 +02:00
|
|
|
else:
|
|
|
|
logger.info("class weights: set default")
|
|
|
|
custom_class_weights = None
|
2017-07-30 13:47:11 +02:00
|
|
|
|
2017-09-01 10:42:26 +02:00
|
|
|
logger.info(f"select model: {args.model_type}")
|
2017-09-05 17:40:57 +02:00
|
|
|
if args.model_type == "staggered":
|
2017-07-30 13:47:11 +02:00
|
|
|
server_tr = np.expand_dims(server_windows_tr, 2)
|
|
|
|
model = new_model
|
2017-09-05 17:40:57 +02:00
|
|
|
logger.info("compile and train model")
|
|
|
|
embedding.summary()
|
|
|
|
model.summary()
|
|
|
|
logger.info(model.get_config())
|
|
|
|
|
|
|
|
model.outputs
|
|
|
|
|
|
|
|
model.compile(optimizer='adam',
|
|
|
|
loss='binary_crossentropy',
|
|
|
|
metrics=['accuracy'] + custom_metrics)
|
|
|
|
|
|
|
|
if args.model_output == "both":
|
|
|
|
labels = [client_tr, server_tr]
|
|
|
|
else:
|
|
|
|
raise ValueError("unknown model output")
|
|
|
|
|
|
|
|
model.fit([domain_tr, flow_tr],
|
|
|
|
labels,
|
|
|
|
batch_size=args.batch_size,
|
|
|
|
epochs=args.epochs,
|
|
|
|
callbacks=callbacks,
|
|
|
|
shuffle=True,
|
|
|
|
validation_split=0.2,
|
|
|
|
class_weight=custom_class_weights)
|
|
|
|
|
2017-09-02 16:02:48 +02:00
|
|
|
else:
|
2017-09-05 17:40:57 +02:00
|
|
|
if args.model_type == "inter":
|
|
|
|
server_tr = np.expand_dims(server_windows_tr, 2)
|
|
|
|
model = new_model
|
|
|
|
logger.info("compile and train model")
|
|
|
|
embedding.summary()
|
|
|
|
model.summary()
|
|
|
|
logger.info(model.get_config())
|
|
|
|
model.compile(optimizer='adam',
|
|
|
|
loss='binary_crossentropy',
|
|
|
|
metrics=['accuracy'] + custom_metrics)
|
|
|
|
|
|
|
|
if args.model_output == "both":
|
|
|
|
labels = [client_tr, server_tr]
|
|
|
|
elif args.model_output == "client":
|
|
|
|
labels = [client_tr]
|
|
|
|
elif args.model_output == "server":
|
|
|
|
labels = [server_tr]
|
|
|
|
else:
|
|
|
|
raise ValueError("unknown model output")
|
|
|
|
|
|
|
|
model.fit([domain_tr, flow_tr],
|
|
|
|
labels,
|
|
|
|
batch_size=args.batch_size,
|
|
|
|
epochs=args.epochs,
|
|
|
|
callbacks=callbacks,
|
|
|
|
shuffle=True,
|
|
|
|
validation_split=0.2,
|
|
|
|
class_weight=custom_class_weights)
|
2017-07-12 10:25:55 +02:00
|
|
|
logger.info("save embedding")
|
2017-07-08 15:04:58 +02:00
|
|
|
embedding.save(args.embedding_model)
|
2017-07-07 16:48:10 +02:00
|
|
|
|
2017-07-05 21:19:19 +02:00
|
|
|
|
2017-07-06 16:27:47 +02:00
|
|
|
def main_test():
|
2017-09-01 10:42:26 +02:00
|
|
|
logger.info("start test: load data")
|
2017-09-02 16:02:48 +02:00
|
|
|
domain_val, flow_val, name_val, client_val, server_val = load_or_generate_h5data(args.test_h5data,
|
|
|
|
args.test_data,
|
|
|
|
args.domain_length,
|
|
|
|
args.window)
|
2017-08-03 09:08:24 +02:00
|
|
|
domain_encs, labels = dataset.load_or_generate_domains(args.test_data, args.domain_length)
|
2017-09-01 10:42:26 +02:00
|
|
|
|
|
|
|
for model_args in get_model_args(args):
|
|
|
|
logger.info(f"process model {model_args['model_path']}")
|
|
|
|
clf_model = load_model(model_args["clf_model"], custom_objects=models.get_metrics())
|
|
|
|
|
|
|
|
pred = clf_model.predict([domain_val, flow_val],
|
|
|
|
batch_size=args.batch_size,
|
|
|
|
verbose=1)
|
|
|
|
|
|
|
|
if args.model_output == "both":
|
|
|
|
c_pred, s_pred = pred
|
|
|
|
elif args.model_output == "client":
|
|
|
|
c_pred = pred
|
|
|
|
s_pred = np.zeros(0)
|
|
|
|
else:
|
|
|
|
c_pred = np.zeros(0)
|
|
|
|
s_pred = pred
|
|
|
|
dataset.save_predictions(model_args["future_prediction"], c_pred, s_pred)
|
|
|
|
|
|
|
|
embd_model = load_model(model_args["embedding_model"])
|
|
|
|
domain_embeddings = embd_model.predict(domain_encs, batch_size=args.batch_size, verbose=1)
|
|
|
|
np.save(model_args["model_path"] + "/domain_embds.npy", domain_embeddings)
|
2017-07-29 19:42:36 +02:00
|
|
|
|
|
|
|
|
2017-07-07 08:43:16 +02:00
|
|
|
def main_visualization():
|
2017-09-02 16:02:48 +02:00
|
|
|
domain_val, flow_val, name_val, client_val, server_val = load_or_generate_h5data(args.test_h5data,
|
|
|
|
args.test_data,
|
|
|
|
args.domain_length,
|
|
|
|
args.window)
|
2017-09-01 10:42:26 +02:00
|
|
|
# client_val, server_val = client_val.value, server_val.value
|
|
|
|
client_val = client_val.value
|
|
|
|
|
2017-09-05 17:40:57 +02:00
|
|
|
logger.info("plot model")
|
|
|
|
model = load_model(args.clf_model, custom_objects=models.get_metrics())
|
|
|
|
visualize.plot_model_as(model, os.path.join(args.model_path, "model.png"))
|
2017-09-01 10:42:26 +02:00
|
|
|
|
2017-07-17 19:30:56 +02:00
|
|
|
try:
|
|
|
|
logger.info("plot training curve")
|
|
|
|
logs = pd.read_csv(args.train_log)
|
2017-08-03 12:27:17 +02:00
|
|
|
if args.model_output == "client":
|
|
|
|
visualize.plot_training_curve(logs, "", "{}/client_train.png".format(args.model_path))
|
|
|
|
else:
|
|
|
|
visualize.plot_training_curve(logs, "client_", "{}/client_train.png".format(args.model_path))
|
|
|
|
visualize.plot_training_curve(logs, "server_", "{}/server_train.png".format(args.model_path))
|
2017-07-17 19:30:56 +02:00
|
|
|
except Exception as e:
|
|
|
|
logger.warning(f"could not generate training curves: {e}")
|
2017-07-14 14:58:17 +02:00
|
|
|
|
2017-08-03 12:27:17 +02:00
|
|
|
client_pred, server_pred = dataset.load_predictions(args.future_prediction)
|
2017-09-04 13:37:26 +02:00
|
|
|
client_pred, server_pred = client_pred.value.flatten(), server_pred.value.flatten()
|
2017-07-12 10:25:55 +02:00
|
|
|
logger.info("plot pr curve")
|
2017-09-01 10:42:26 +02:00
|
|
|
visualize.plot_clf()
|
|
|
|
visualize.plot_precision_recall(client_val, client_pred)
|
|
|
|
visualize.plot_save("{}/client_prc.png".format(args.model_path))
|
2017-07-30 15:49:37 +02:00
|
|
|
# visualize.plot_precision_recall(server_val, server_pred, "{}/server_prc.png".format(args.model_path))
|
|
|
|
# visualize.plot_precision_recall_curves(client_val, client_pred, "{}/client_prc2.png".format(args.model_path))
|
|
|
|
# visualize.plot_precision_recall_curves(server_val, server_pred, "{}/server_prc2.png".format(args.model_path))
|
2017-07-12 10:25:55 +02:00
|
|
|
logger.info("plot roc curve")
|
2017-09-01 10:42:26 +02:00
|
|
|
visualize.plot_clf()
|
|
|
|
visualize.plot_roc_curve(client_val, client_pred)
|
|
|
|
visualize.plot_save("{}/client_roc.png".format(args.model_path))
|
2017-07-30 15:49:37 +02:00
|
|
|
# visualize.plot_roc_curve(server_val, server_pred, "{}/server_roc.png".format(args.model_path))
|
2017-09-02 16:02:48 +02:00
|
|
|
|
|
|
|
print(f"names {name_val.shape} vals {client_val.shape} preds {client_pred.shape}")
|
|
|
|
|
|
|
|
df_val = pd.DataFrame(data={"names": name_val, "client_val": client_val})
|
|
|
|
user_vals = df_val.groupby(df_val.names).max().client_val.as_matrix().astype(float)
|
2017-09-04 13:37:26 +02:00
|
|
|
df_pred = pd.DataFrame(data={"names": name_val, "client_val": client_pred})
|
2017-09-02 16:02:48 +02:00
|
|
|
user_preds = df_pred.groupby(df_pred.names).max().client_val.as_matrix().astype(float)
|
|
|
|
|
|
|
|
visualize.plot_clf()
|
|
|
|
visualize.plot_precision_recall(user_vals, user_preds)
|
|
|
|
visualize.plot_save("{}/user_client_prc.png".format(args.model_path))
|
|
|
|
|
|
|
|
visualize.plot_clf()
|
|
|
|
visualize.plot_roc_curve(user_vals, user_preds)
|
|
|
|
visualize.plot_save("{}/user_client_roc.png".format(args.model_path))
|
|
|
|
|
2017-07-30 15:49:37 +02:00
|
|
|
visualize.plot_confusion_matrix(client_val, client_pred.flatten().round(),
|
2017-07-14 15:57:52 +02:00
|
|
|
"{}/client_cov.png".format(args.model_path),
|
|
|
|
normalize=False, title="Client Confusion Matrix")
|
2017-07-30 15:49:37 +02:00
|
|
|
# visualize.plot_confusion_matrix(server_val.argmax(1), server_pred.argmax(1),
|
|
|
|
# "{}/server_cov.png".format(args.model_path),
|
|
|
|
# normalize=False, title="Server Confusion Matrix")
|
2017-09-05 17:40:57 +02:00
|
|
|
logger.info("visualize embedding")
|
|
|
|
domain_encs, labels = dataset.load_or_generate_domains(args.test_data, args.domain_length)
|
|
|
|
domain_embedding = np.load(args.model_path + "/domain_embds.npy")
|
|
|
|
visualize.plot_embedding(domain_embedding, labels, path="{}/embd.png".format(args.model_path))
|
2017-07-07 08:43:16 +02:00
|
|
|
|
|
|
|
|
2017-09-01 10:42:26 +02:00
|
|
|
def main_visualize_all():
|
2017-09-02 16:02:48 +02:00
|
|
|
domain_val, flow_val, name_val, client_val, server_val = load_or_generate_h5data(args.test_h5data,
|
|
|
|
args.test_data,
|
|
|
|
args.domain_length,
|
|
|
|
args.window)
|
2017-09-01 10:42:26 +02:00
|
|
|
logger.info("plot pr curves")
|
|
|
|
visualize.plot_clf()
|
|
|
|
for model_args in get_model_args(args):
|
|
|
|
client_pred, server_pred = dataset.load_predictions(model_args["future_prediction"])
|
|
|
|
visualize.plot_precision_recall(client_val.value, client_pred.value, model_args["model_path"])
|
|
|
|
visualize.plot_legend()
|
2017-09-05 17:40:57 +02:00
|
|
|
visualize.plot_save(f"{args.output_prefix}_client_prc.png")
|
2017-09-01 10:42:26 +02:00
|
|
|
|
|
|
|
logger.info("plot roc curves")
|
|
|
|
visualize.plot_clf()
|
|
|
|
for model_args in get_model_args(args):
|
|
|
|
client_pred, server_pred = dataset.load_predictions(model_args["future_prediction"])
|
|
|
|
visualize.plot_roc_curve(client_val.value, client_pred.value, model_args["model_path"])
|
|
|
|
visualize.plot_legend()
|
2017-09-05 17:40:57 +02:00
|
|
|
visualize.plot_save(f"{args.output_prefix}_client_roc.png")
|
2017-09-01 10:42:26 +02:00
|
|
|
|
2017-09-04 13:37:26 +02:00
|
|
|
df_val = pd.DataFrame(data={"names": name_val, "client_val": client_val})
|
|
|
|
user_vals = df_val.groupby(df_val.names).max().client_val.as_matrix().astype(float)
|
|
|
|
|
|
|
|
logger.info("plot user pr curves")
|
|
|
|
visualize.plot_clf()
|
|
|
|
for model_args in get_model_args(args):
|
|
|
|
client_pred, server_pred = dataset.load_predictions(model_args["future_prediction"])
|
|
|
|
df_pred = pd.DataFrame(data={"names": name_val, "client_val": client_pred.value.flatten()})
|
|
|
|
user_preds = df_pred.groupby(df_pred.names).max().client_val.as_matrix().astype(float)
|
|
|
|
visualize.plot_precision_recall(user_vals, user_preds, model_args["model_path"])
|
|
|
|
visualize.plot_legend()
|
2017-09-05 17:40:57 +02:00
|
|
|
visualize.plot_save(f"{args.output_prefix}_user_client_prc.png")
|
2017-09-04 13:37:26 +02:00
|
|
|
|
|
|
|
logger.info("plot user roc curves")
|
|
|
|
visualize.plot_clf()
|
|
|
|
for model_args in get_model_args(args):
|
|
|
|
client_pred, server_pred = dataset.load_predictions(model_args["future_prediction"])
|
|
|
|
df_pred = pd.DataFrame(data={"names": name_val, "client_val": client_pred.value.flatten()})
|
|
|
|
user_preds = df_pred.groupby(df_pred.names).max().client_val.as_matrix().astype(float)
|
|
|
|
visualize.plot_roc_curve(user_vals, user_preds, model_args["model_path"])
|
|
|
|
visualize.plot_legend()
|
2017-09-05 17:40:57 +02:00
|
|
|
visualize.plot_save(f"{args.output_prefix}_user_client_roc.png")
|
2017-09-04 13:37:26 +02:00
|
|
|
|
2017-09-01 10:42:26 +02:00
|
|
|
|
2017-07-16 09:42:52 +02:00
|
|
|
def main_data():
|
|
|
|
char_dict = dataset.get_character_dict()
|
|
|
|
user_flow_df = dataset.get_user_flow_data(args.train_data)
|
|
|
|
logger.info("create training dataset")
|
2017-09-02 16:02:48 +02:00
|
|
|
domain_tr, flow_tr, name_tr, client_tr, server_tr = dataset.create_dataset_from_flows(user_flow_df, char_dict,
|
|
|
|
max_len=args.domain_length,
|
|
|
|
window_size=args.window)
|
2017-07-16 09:42:52 +02:00
|
|
|
print(f"domain shape {domain_tr.shape}")
|
|
|
|
print(f"flow shape {flow_tr.shape}")
|
|
|
|
print(f"client shape {client_tr.shape}")
|
|
|
|
print(f"server shape {server_tr.shape}")
|
|
|
|
|
|
|
|
|
2017-07-07 08:43:16 +02:00
|
|
|
def main():
|
2017-07-30 15:49:37 +02:00
|
|
|
if "train" == args.mode:
|
2017-07-07 16:48:10 +02:00
|
|
|
main_train()
|
2017-07-30 15:49:37 +02:00
|
|
|
if "hyperband" == args.mode:
|
2017-07-07 16:48:10 +02:00
|
|
|
main_hyperband()
|
2017-07-30 15:49:37 +02:00
|
|
|
if "test" == args.mode:
|
2017-07-07 16:48:10 +02:00
|
|
|
main_test()
|
2017-07-30 15:49:37 +02:00
|
|
|
if "fancy" == args.mode:
|
2017-07-07 16:48:10 +02:00
|
|
|
main_visualization()
|
2017-09-01 10:42:26 +02:00
|
|
|
if "all_fancy" == args.mode:
|
|
|
|
main_visualize_all()
|
2017-07-30 15:49:37 +02:00
|
|
|
if "paul" == args.mode:
|
2017-07-08 11:53:03 +02:00
|
|
|
main_paul_best()
|
2017-07-30 15:49:37 +02:00
|
|
|
if "data" == args.mode:
|
2017-07-16 09:42:52 +02:00
|
|
|
main_data()
|
2017-07-07 08:43:16 +02:00
|
|
|
|
|
|
|
|
2017-06-30 10:12:20 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|