Thiết kế quy trình Machine Learning bằng Python
Dr. Chris Anagnostopoulos
Honorary Associate Professor

flows: Phiên truyền dữ liệu liên tục giữa một cổng trên máy nguồn và một cổng trên máy đích, theo một giao thức nhất định.
flows.iloc[1]
time 471692
duration 0
source_computer C5808
source_port N2414
destination_computer C26871
destination_port N19148
protocol 6
packet_count 1
byte_count 60
attack: thông tin về một số tấn công do chính đội an ninh thực hiện trong quá trình thử nghiệm.
attacks.head()
time user@domain source_computer destination_computer
0 151036 U748@DOM1 C17693 C305
1 151648 U748@DOM1 C17693 C728
2 151993 U6115@DOM1 C17693 C1173
3 153792 U636@DOM1 C17693 C294
4 155219 U748@DOM1 C17693 C5693
Làm thế nào để tạo ví dụ có nhãn từ dữ liệu này?
Một sự kiện đơn lẻ khó gán nhãn.

Nhưng một máy tính thì hoặc bị nhiễm hoặc không.

Đơn vị phân tích = destination_computer
flows_grouped = flows.groupby('destination_computer')list(flows_grouped)[0]
('C10047',
time duration ... packet_count byte_count
2791 471694 0 ... 12 6988
2792 471694 0 ... 1 193
...
2846 471694 38 ... 157 84120
Từ một DataFrame mỗi máy tính, thành một vector đặc trưng mỗi máy tính.
def featurize(df):
return {
'unique_ports': len(set(df['destination_port'])),
'average_packet': np.mean(df['packet_count']),
'average_duration': np.mean(df['duration'])
}
out = flows.groupby('destination_computer').apply(featurize)
X = pd.DataFrame(list(out), index=out.index)X.head()
average_duration ... unique_ports
destination_computer ...
C10047 7.538462 ... 13
C10054 0.000000 ... 1
C10131 55.000000 ... 1
...
[5 rows x 3 columns]
bads = set(attacks['source_computer'].append(attacks['destination_computer']))
y = [x in bads for x in X.index]
Cặp (X, y) giờ là một tập dữ liệu phân loại có gán nhãn chuẩn.
X_train, X_test, y_train, y_test = train_test_split(X, y)
clf = AdaBoostClassifier()
accuracy_score(y_test, clf.fit(X_train, y_train).predict(X_test))
0.92
Thiết kế quy trình Machine Learning bằng Python