Skip to content

Commit 0f28b18

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

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-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: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
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, "Some error while importing"
24+
print >> sys.stderr, e
25+
26+
1827
try:
19-
import matplotlib.pyplot as plt
2028
import numpy as np
2129
import pandas as pd
22-
import seaborn as sns
2330
from hdbscan import HDBSCAN
2431
from sklearn import metrics
2532
from sklearn.cluster import DBSCAN
@@ -797,6 +804,14 @@ def filter_dataset(self, dataset=None, feature_coverage=0.1,
797804

798805
def detect_abnormal_behaviour(self, count_dataset=None, figures=True):
799806
"""Detect samples that behave significantly different than others."""
807+
808+
# Safety check for plotting
809+
if not Config("cuckooml").cuckooml.plotting and figures:
810+
print >> sys.stderr, "Warning: 'plotting' and 'figures' do not match. \
811+
Plotting modules might not be imported."
812+
figures = False
813+
814+
800815
if count_dataset is None:
801816
# Pull all count features
802817
count_features = self.feature_category(":count:")
@@ -1133,6 +1148,14 @@ def performance_metric(clustering, labels, data, noise):
11331148

11341149
def clustering_label_distribution(self, clustering, labels, plot=False):
11351150
"""Get statistics about number of ground truth labels per cluster."""
1151+
1152+
# Safety check for plotting
1153+
if not Config("cuckooml").cuckooml.plotting and plot:
1154+
print >> sys.stderr, "Warning: 'plotting' and 'plot' do not match.\
1155+
Plotting modules might not be imported."
1156+
plot = False
1157+
1158+
11361159
cluster_ids = set(clustering["label"].tolist())
11371160
labels_ids = set(labels["label"].tolist())
11381161
cluster_distribution = {}

0 commit comments

Comments
 (0)