def computeFpFn(self):
thresholds = sorted(list(set([float(round(Decimal(x), 3)) for x in self.all_predictions] + [0.0, 1.0])))
## Detection Rates
self.detection_rates = pd.DataFrame(
np.zeros((len(thresholds), len(self.malicious_families) + 1)),
index = thresholds,
columns = self.malicious_families.keys() + ['Mean'])
for family in self.malicious_families.keys():
predictions = sorted(self.malicious_families[family])
num_predictions = len(predictions)
predictions_u = sorted(list(set(predictions)))
f_thresholds = [0.0] + [(t+s)/2 for s, t in zip(predictions_u[:-1], predictions_u[1:])] + [1.0]
perf = np.array([0] * len(f_thresholds))
index = 0
for p in predictions:
while f_thresholds[index] < p:
index += 1
perf[index:] += 1
perf = 1 - perf / num_predictions
perf = interp(thresholds, f_thresholds, perf)
self.detection_rates[family] = perf
self.detection_rates['Mean'] = self.detection_rates.loc[:, self.malicious_families.keys()].mean(axis = 1)
## False Alarm Rates
self.false_alarm_rates = pd.DataFrame(
np.zeros((len(thresholds), len(self.benign_families) + 1)),
index = thresholds,
columns = self.benign_families.keys() + ['Mean'])
for family in self.benign_families.keys():
predictions = sorted(self.benign_families[family])
num_predictions = len(predictions)
predictions_u = sorted(list(set(predictions)))
f_thresholds = [0.0] + [(t+s)/2 for s, t in zip(predictions_u[:-1], predictions_u[1:])] + [1.0]
perf = np.array([0] * len(f_thresholds))
index = 0
for p in predictions:
while f_thresholds[index] < p:
index += 1
perf[index:] += 1
perf = 1 - perf / num_predictions
perf = interp(thresholds, f_thresholds, perf)
self.false_alarm_rates[family] = perf
self.false_alarm_rates['Mean'] = self.false_alarm_rates.loc[:, self.benign_families.keys()].mean(axis = 1)
评论列表
文章目录