Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना
Dr. Chris Anagnostopoulos
Honorary Associate Professor

flows: फ्लोज़ वे सेशन्स हैं जिनमें एक स्रोत कंप्यूटर के पोर्ट से एक गंतव्य कंप्यूटर के पोर्ट तक, किसी प्रोटोकॉल के अनुसार, लगातार डेटा ट्रांसफ़र होता है.
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: टेस्ट के दौरान सुरक्षा टीम द्वारा खुद किए गए कुछ हमलों की जानकारी.
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
हम इस डेटा से लेबल वाले उदाहरण कैसे बनाएँ?
एकल इवेंट को आसानी से लेबल नहीं किया जा सकता.

लेकिन पूरा कंप्यूटर या तो संक्रमित है या नहीं.

विश्लेषण की इकाई = 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
प्रति कंप्यूटर एक DataFrame से, प्रति कंप्यूटर एक फीचर वेक्टर तक.
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]
जोड़ी (X, y) अब एक मानक लेबल्ड क्लासिफिकेशन डेटासेट है.
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
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना