|
15 | 15 | from lib.cuckoo.common.constants import CUCKOO_ROOT |
16 | 16 | from math import log |
17 | 17 |
|
| 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 | + |
18 | 28 | try: |
19 | | - import matplotlib.pyplot as plt |
20 | 29 | import numpy as np |
21 | 30 | import pandas as pd |
22 | | - import seaborn as sns |
23 | 31 | from hdbscan import HDBSCAN |
24 | 32 | from sklearn import metrics |
25 | 33 | from sklearn.cluster import DBSCAN |
@@ -797,6 +805,14 @@ def filter_dataset(self, dataset=None, feature_coverage=0.1, |
797 | 805 |
|
798 | 806 | def detect_abnormal_behaviour(self, count_dataset=None, figures=True): |
799 | 807 | """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 | + |
800 | 816 | if count_dataset is None: |
801 | 817 | # Pull all count features |
802 | 818 | count_features = self.feature_category(":count:") |
@@ -1133,6 +1149,14 @@ def performance_metric(clustering, labels, data, noise): |
1133 | 1149 |
|
1134 | 1150 | def clustering_label_distribution(self, clustering, labels, plot=False): |
1135 | 1151 | """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 | + |
1136 | 1160 | cluster_ids = set(clustering["label"].tolist()) |
1137 | 1161 | labels_ids = set(labels["label"].tolist()) |
1138 | 1162 | cluster_distribution = {} |
|
0 commit comments