Skip to content

Commit 709f52f

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

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-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+
# Do plotting?
43+
plotting = true

modules/processing/cuckooml.py

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

18+
if Config("cuckooml").cuckooml.plotting:
19+
try:
20+
import matplotlib.pyplot as plt
21+
import seaborn as sns
22+
except ImportError, e:
23+
print >> sys.stderr, "Plotting libraries \
24+
(matplotlib and seaborn) are not available."
25+
print >> sys.stderr, e
26+
27+
1828
try:
19-
import matplotlib.pyplot as plt
2029
import numpy as np
2130
import pandas as pd
22-
import seaborn as sns
2331
from hdbscan import HDBSCAN
2432
from sklearn import metrics
2533
from sklearn.cluster import DBSCAN
@@ -797,6 +805,14 @@ def filter_dataset(self, dataset=None, feature_coverage=0.1,
797805

798806
def detect_abnormal_behaviour(self, count_dataset=None, figures=True):
799807
"""Detect samples that behave significantly different than others."""
808+
809+
# Safety check for plotting
810+
if not Config("cuckooml").cuckooml.plotting and figures:
811+
print >> sys.stderr, "Warning:'plotting' flag disabled in config file, \
812+
'figures' flag will be overwritten."
813+
figures = False
814+
815+
800816
if count_dataset is None:
801817
# Pull all count features
802818
count_features = self.feature_category(":count:")
@@ -1133,6 +1149,14 @@ def performance_metric(clustering, labels, data, noise):
11331149

11341150
def clustering_label_distribution(self, clustering, labels, plot=False):
11351151
"""Get statistics about number of ground truth labels per cluster."""
1152+
1153+
# Safety check for plotting
1154+
if not Config("cuckooml").cuckooml.plotting and plot:
1155+
print >> sys.stderr, "Warning:'plotting' flag disabled in config file, \
1156+
'plot' flag will be overwritten."
1157+
plot = False
1158+
1159+
11361160
cluster_ids = set(clustering["label"].tolist())
11371161
labels_ids = set(labels["label"].tolist())
11381162
cluster_distribution = {}

0 commit comments

Comments
 (0)