Skip to content

Commit e840ae2

Browse files
committed
Features added referring to #15
1 parent 1c793b5 commit e840ae2

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

conf/.cuckoo.conf.swp

16 KB
Binary file not shown.

conf/cuckooml.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ compare_new_samples = true
3838

3939
# Set folder for samples to be compared against clustering
4040
test_directory = sample_data/test
41+
42+
# Enable plotting functionality
43+
plotting = true

modules/processing/cuckooml.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,23 @@
1515
from lib.cuckoo.common.constants import CUCKOO_ROOT
1616
from math import log
1717

18+
global imported
19+
imported = True
20+
21+
if Config("cuckooml").cuckooml.plotting:
22+
try:
23+
import matplotlib.pyplot as plt
24+
import seaborn as sns
25+
except ImportError, e:
26+
print >> sys.stderr, "Plotting libraries \
27+
(matplotlib and seaborn) are not available."
28+
print >> sys.stderr, e
29+
imported = False
30+
31+
1832
try:
19-
import matplotlib.pyplot as plt
2033
import numpy as np
2134
import pandas as pd
22-
import seaborn as sns
2335
from hdbscan import HDBSCAN
2436
from sklearn import metrics
2537
from sklearn.cluster import DBSCAN
@@ -797,6 +809,17 @@ def filter_dataset(self, dataset=None, feature_coverage=0.1,
797809

798810
def detect_abnormal_behaviour(self, count_dataset=None, figures=True):
799811
"""Detect samples that behave significantly different than others."""
812+
813+
# Safety check for plotting
814+
if not imported:
815+
figures = False
816+
else:
817+
if not Config("cuckooml").cuckooml.plotting and figures:
818+
print >> sys.stderr, "Warning:'plotting' flag disabled in conf/cuckooml.conf, \
819+
'figures' flag will be overwritten."
820+
figures = False
821+
822+
800823
if count_dataset is None:
801824
# Pull all count features
802825
count_features = self.feature_category(":count:")
@@ -1133,6 +1156,17 @@ def performance_metric(clustering, labels, data, noise):
11331156

11341157
def clustering_label_distribution(self, clustering, labels, plot=False):
11351158
"""Get statistics about number of ground truth labels per cluster."""
1159+
1160+
# Safety check for plotting
1161+
if not imported:
1162+
plot = False
1163+
else:
1164+
if not Config("cuckooml").cuckooml.plotting and plot:
1165+
print >> sys.stderr, "Warning:'plotting' flag disabled in conf/cuckooml.conf, \
1166+
'plot' flag will be overwritten."
1167+
plot = False
1168+
1169+
11361170
cluster_ids = set(clustering["label"].tolist())
11371171
labels_ids = set(labels["label"].tolist())
11381172
cluster_distribution = {}

0 commit comments

Comments
 (0)