1.数据集使用ADFA-LD数据集
def load_all_files():
import glob
x=[]
y=[]
files=glob.glob("ADFA-LD/Attack_Data_Master/*/*")
for file in files:
with open(file) as f:
lines=f.readlines()
x.append(" ".join(lines))
y.append(1)
print("Load black data %d" % len(x))
files=glob.glob("ADFA-LD/Training_Data_Master/*")
for file in files:
with open(file) as f:
lines=f.readlines()
x.append(" ".join(lines))
y.append(0)
print("Load full data %d" % len(x))
return x,y
2.使用N-Gram和TF-IDF提取特征
def get_feature_wordbag():
max_features=1000
x,y=load_all_files()
vectorizer = CountVectorizer(
ngram_range=(3, 3),
token_pattern=r'\b\d+\b',
decode_error='ignore',
strip_accents='ascii',