|
15 | 15 | from lib.cuckoo.common.constants import CUCKOO_ROOT
|
16 | 16 | from math import log
|
17 | 17 |
|
| 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 | + |
18 | 32 | try:
|
19 |
| - import matplotlib.pyplot as plt |
20 | 33 | import numpy as np
|
21 | 34 | import pandas as pd
|
22 |
| - import seaborn as sns |
23 | 35 | from hdbscan import HDBSCAN
|
24 | 36 | from sklearn import metrics
|
25 | 37 | from sklearn.cluster import DBSCAN
|
@@ -797,6 +809,17 @@ def filter_dataset(self, dataset=None, feature_coverage=0.1,
|
797 | 809 |
|
798 | 810 | def detect_abnormal_behaviour(self, count_dataset=None, figures=True):
|
799 | 811 | """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 | + |
800 | 823 | if count_dataset is None:
|
801 | 824 | # Pull all count features
|
802 | 825 | count_features = self.feature_category(":count:")
|
@@ -1133,6 +1156,17 @@ def performance_metric(clustering, labels, data, noise):
|
1133 | 1156 |
|
1134 | 1157 | def clustering_label_distribution(self, clustering, labels, plot=False):
|
1135 | 1158 | """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 | + |
1136 | 1170 | cluster_ids = set(clustering["label"].tolist())
|
1137 | 1171 | labels_ids = set(labels["label"].tolist())
|
1138 | 1172 | cluster_distribution = {}
|
|
0 commit comments