-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClean_Label_Poisoning_Mapping.py
More file actions
58 lines (41 loc) · 1.51 KB
/
Clean_Label_Poisoning_Mapping.py
File metadata and controls
58 lines (41 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pickle
from RPAL import data, loader, poison
'''
Clean Label Attack Sample Generation
'''
# Setup control variables
random_state = 999
# Percent of points to retrain on each month
al_strengths = [str(2 ** x) for x in range(0, 5)]
al_strengths[0] = str(0)
# Percents of generation malware set to be added as poisoning points
poisoning_strength = 0.16
p_settings = [0.02, 0.04, 0.08, 0.16]
p_amounts = [1156, 2312, 4626, 9252]
# File path for dataset
file_path = 'Dataset/extended-features'
extension = '.p'
X_extension = 'reduced'
# Underlying malware distribution
mw_distribution = 0.1
def_dist = 100000
def main():
print("Starting....")
# Load dataset
print("Loading Data...")
X, y, t = loader.load_p(fname=file_path, X_extension=X_extension)
if X_extension == 'full':
X = data.format_features(X)
# Partition dataset
print("Splitting Dataset....")
splits = data.prepare_splits(X, y, t, random_state)
results = poison.label_flip_feature_mapping(p_settings=p_settings,
p_amounts=p_amounts,
splits=splits,
mw_distribution=mw_distribution,
file_path=file_path,
random_state=random_state)
with open(file_path + '-Label-Flip-Poison-Feature-Mapping.p', 'wb') as fp:
pickle.dump(results, fp)
if __name__ == '__main__':
main()