Skip to content

Commit a54b83f

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

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

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: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,24 @@
1515
from lib.cuckoo.common.constants import CUCKOO_ROOT
1616
from math import log
1717

18+
global PLOTTING_LIBRARIES_IMPORTED
19+
PLOTTING_LIBRARIES_IMPORTED = False
20+
21+
if Config("cuckooml").cuckooml.plotting:
22+
try:
23+
import matplotlib.pyplot as plt
24+
import seaborn as sns
25+
PLOTTING_LIBRARIES_IMPORTED = True
26+
except ImportError, e:
27+
print >> sys.stderr, "Plotting libraries \
28+
(matplotlib and seaborn) are not available."
29+
print >> sys.stderr, e
30+
PLOTTING_LIBRARIES_IMPORTED = False
31+
32+
1833
try:
19-
import matplotlib.pyplot as plt
2034
import numpy as np
2135
import pandas as pd
22-
import seaborn as sns
2336
from hdbscan import HDBSCAN
2437
from sklearn import metrics
2538
from sklearn.cluster import DBSCAN
@@ -797,6 +810,19 @@ def filter_dataset(self, dataset=None, feature_coverage=0.1,
797810

798811
def detect_abnormal_behaviour(self, count_dataset=None, figures=True):
799812
"""Detect samples that behave significantly different than others."""
813+
814+
# Safety check for plotting
815+
if not PLOTTING_LIBRARIES_IMPORTED and figures:
816+
print >> sys.stderr, "Warning: plotting libraries were not imported. \n" \
817+
"Plots wont be produced."
818+
819+
if not Config("cuckooml").cuckooml.plotting:
820+
print >> sys.stderr, " Plotting is disabled in cuckooml config."
821+
else:
822+
print >> sys.stderr, "Plotting libraries are missing."
823+
figures = False
824+
825+
800826
if count_dataset is None:
801827
# Pull all count features
802828
count_features = self.feature_category(":count:")
@@ -1133,6 +1159,18 @@ def performance_metric(clustering, labels, data, noise):
11331159

11341160
def clustering_label_distribution(self, clustering, labels, plot=False):
11351161
"""Get statistics about number of ground truth labels per cluster."""
1162+
1163+
# Safety check for plotting
1164+
if not PLOTTING_LIBRARIES_IMPORTED and plot:
1165+
print >> sys.stderr, "Warning: plotting libraries were not imported. \n" \
1166+
"Plots wont be produced."
1167+
1168+
if not Config("cuckooml").cuckooml.plotting:
1169+
print >> sys.stderr, " Plotting is disabled in cuckooml config."
1170+
else:
1171+
print >> sys.stderr, "Plotting libraries are missing."
1172+
plot = False
1173+
11361174
cluster_ids = set(clustering["label"].tolist())
11371175
labels_ids = set(labels["label"].tolist())
11381176
cluster_distribution = {}

0 commit comments

Comments
 (0)