-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dark_ppt.py
More file actions
360 lines (308 loc) · 11.8 KB
/
Copy pathcreate_dark_ppt.py
File metadata and controls
360 lines (308 loc) · 11.8 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.text import PP_ALIGN
from pptx.dml.color import RGBColor
from pptx.enum.shapes import MSO_SHAPE
import os
# Create presentation
prs = Presentation()
prs.slide_width = Inches(10)
prs.slide_height = Inches(7.5)
# Dark Cyber Theme Colors
DARK_BG = RGBColor(10, 15, 25)
CYBER_GREEN = RGBColor(0, 255, 153)
CYBER_CYAN = RGBColor(0, 255, 255)
CYBER_PURPLE = RGBColor(138, 43, 226)
TEXT_WHITE = RGBColor(240, 240, 240)
TEXT_GRAY = RGBColor(180, 180, 180)
def add_dark_background(slide):
bg = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, 0, 0, prs.slide_width, prs.slide_height)
bg.fill.solid()
bg.fill.fore_color.rgb = DARK_BG
bg.line.fill.background()
slide.shapes._spTree.remove(bg._element)
slide.shapes._spTree.insert(2, bg._element)
def add_title_slide(prs, title, subtitle):
slide = prs.slides.add_slide(prs.slide_layouts[6])
add_dark_background(slide)
accent_bar = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), Inches(3.2), prs.slide_width, Inches(0.05))
accent_bar.fill.solid()
accent_bar.fill.fore_color.rgb = CYBER_GREEN
accent_bar.line.fill.background()
title_box = slide.shapes.add_textbox(Inches(0.5), Inches(2), Inches(9), Inches(1))
title_frame = title_box.text_frame
title_frame.text = title
title_p = title_frame.paragraphs[0]
title_p.font.size = Pt(48)
title_p.font.bold = True
title_p.font.color.rgb = CYBER_GREEN
title_p.alignment = PP_ALIGN.CENTER
subtitle_box = slide.shapes.add_textbox(Inches(0.5), Inches(3.5), Inches(9), Inches(1))
subtitle_frame = subtitle_box.text_frame
subtitle_frame.text = subtitle
sub_p = subtitle_frame.paragraphs[0]
sub_p.font.size = Pt(24)
sub_p.font.color.rgb = CYBER_CYAN
sub_p.alignment = PP_ALIGN.CENTER
def add_content_slide(prs, title, content_list):
slide = prs.slides.add_slide(prs.slide_layouts[6])
add_dark_background(slide)
title_box = slide.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(8), Inches(0.7))
title_frame = title_box.text_frame
title_frame.text = title
title_p = title_frame.paragraphs[0]
title_p.font.size = Pt(30)
title_p.font.bold = True
title_p.font.color.rgb = CYBER_GREEN
accent = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0.5), Inches(1), Inches(9), Inches(0.02))
accent.fill.solid()
accent.fill.fore_color.rgb = CYBER_CYAN
accent.line.fill.background()
content_box = slide.shapes.add_textbox(Inches(0.8), Inches(1.5), Inches(8.4), Inches(5.5))
text_frame = content_box.text_frame
text_frame.word_wrap = True
for item in content_list:
p = text_frame.add_paragraph()
p.text = item
p.font.size = Pt(16)
p.font.color.rgb = TEXT_WHITE
p.space_before = Pt(8)
p.space_after = Pt(8)
def add_image_slide(prs, title, image_path, caption=''):
slide = prs.slides.add_slide(prs.slide_layouts[6])
add_dark_background(slide)
title_box = slide.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(9), Inches(0.7))
title_frame = title_box.text_frame
title_frame.text = title
title_p = title_frame.paragraphs[0]
title_p.font.size = Pt(28)
title_p.font.bold = True
title_p.font.color.rgb = CYBER_GREEN
accent = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0.5), Inches(1), Inches(9), Inches(0.02))
accent.fill.solid()
accent.fill.fore_color.rgb = CYBER_CYAN
accent.line.fill.background()
if os.path.exists(image_path):
slide.shapes.add_picture(image_path, Inches(1), Inches(1.5), height=Inches(5))
if caption:
caption_box = slide.shapes.add_textbox(Inches(0.5), Inches(6.8), Inches(9), Inches(0.5))
caption_frame = caption_box.text_frame
caption_frame.text = caption
cap_p = caption_frame.paragraphs[0]
cap_p.font.size = Pt(14)
cap_p.font.color.rgb = TEXT_GRAY
cap_p.alignment = PP_ALIGN.CENTER
def add_two_column_slide(prs, title, left_content, right_content):
slide = prs.slides.add_slide(prs.slide_layouts[6])
add_dark_background(slide)
title_box = slide.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(9), Inches(0.7))
title_frame = title_box.text_frame
title_frame.text = title
title_p = title_frame.paragraphs[0]
title_p.font.size = Pt(28)
title_p.font.bold = True
title_p.font.color.rgb = CYBER_GREEN
accent = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0.5), Inches(1), Inches(9), Inches(0.02))
accent.fill.solid()
accent.fill.fore_color.rgb = CYBER_CYAN
accent.line.fill.background()
left_box = slide.shapes.add_textbox(Inches(0.5), Inches(1.5), Inches(4.5), Inches(5.5))
left_frame = left_box.text_frame
left_frame.word_wrap = True
for item in left_content:
p = left_frame.add_paragraph()
p.text = item
p.font.size = Pt(14)
p.font.color.rgb = TEXT_WHITE
p.space_before = Pt(6)
sep = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(4.95), Inches(1.5), Inches(0.02), Inches(5.5))
sep.fill.solid()
sep.fill.fore_color.rgb = CYBER_PURPLE
sep.line.fill.background()
right_box = slide.shapes.add_textbox(Inches(5.2), Inches(1.5), Inches(4.3), Inches(5.5))
right_frame = right_box.text_frame
right_frame.word_wrap = True
for item in right_content:
p = right_frame.add_paragraph()
p.text = item
p.font.size = Pt(14)
p.font.color.rgb = TEXT_WHITE
p.space_before = Pt(6)
print('🎨 Creating Dark Cyber Security Presentation...')
# Slides
add_title_slide(prs, '🔒 NETWORK ANOMALY DETECTION', 'Ensemble Machine Learning on NSL-KDD Dataset')
add_content_slide(prs, '💡 Introduction & Motivation', [
'🎯 Network security threats evolve constantly',
'⚠️ Traditional systems fail against zero-day attacks',
'🤖 ML provides adaptive detection',
'🔍 Anomaly detection works without prior signatures',
'⚡ Goal: Production-ready system <1ms latency'
])
add_content_slide(prs, '🎯 Problem Statement', [
'❌ Real-time network intrusion detection',
'⚖️ Balance precision vs recall',
'📊 Handle 41 high-dimensional features',
'🔄 Manage class imbalance',
'⚡ Sub-second inference latency',
'🎛️ Tunable sensitivity'
])
add_content_slide(prs, '📊 Dataset: NSL-KDD', [
'📦 Enhanced KDD Cup 1999',
'🔹 Training: 148,517 samples (51.9% normal)',
'🔹 Testing: 29,704 samples (55.2% normal)',
'🔢 Features: 41 (38 numeric, 3 categorical)',
'🎯 Attacks: DoS, Probe, R2L, U2R',
'✅ Binary: Normal vs Anomaly'
])
add_content_slide(prs, '⚙️ Methodology', [
'🌲 ISOLATION FOREST',
' • 50 estimators, 256 samples',
'',
'📍 LOCAL OUTLIER FACTOR',
' • 10 neighbors, multi-threaded',
'',
'🔗 ENSEMBLE METHODS',
' • Voting, Averaging, Threshold, Stacking'
])
add_content_slide(prs, '🏗️ System Architecture', [
'1️⃣ Preprocessing (encoding, scaling)',
'2️⃣ Model Training (parallel)',
'3️⃣ Ensemble Layer (4 strategies)',
'4️⃣ REST API (FastAPI)'
])
add_image_slide(prs, '📊 Class Distribution', 'results/class_distribution.png',
'Training: 54% normal, 46% anomaly')
add_image_slide(prs, '📈 Feature Distribution', 'results/feature_distribution.png',
'Duration, bytes, errors show distinct patterns')
add_content_slide(prs, '🏆 Model Performance', [
'🥇 ISOLATION FOREST',
' • F1: 0.2446 | ROC: 0.8476',
' • Precision: 71% | Recall: 15%',
' • TP: 2,110 | TN: 14,558',
'',
'🥈 LOF: F1=0.1067 | ROC=0.4563',
'🥉 AE Baseline: F1=0.0451'
])
add_image_slide(prs, '🔍 Confusion Matrices', 'results/confusion_matrices.png',
'IF shows strong diagonal performance')
add_image_slide(prs, '📉 ROC Curves', 'results/roc_curves.png',
'IF: 0.8476 AUC (excellent discrimination)')
add_image_slide(prs, '⚖️ Precision-Recall', 'results/precision_recall_curves.png',
'IF >70% precision at low recall')
add_image_slide(prs, '📊 Anomaly Scores', 'results/anomaly_scores.png',
'IF shows clear separation')
add_image_slide(prs, '📊 Metrics Comparison', 'results/metrics_comparison.png',
'IF leads in all metrics')
add_image_slide(prs, '🎨 PCA Visualization', 'results/pca_visualization.png',
'Moderate class separability')
add_image_slide(prs, '🎯 PCA Predictions', 'results/pca_anomalies.png',
'TP cluster in anomaly regions')
add_two_column_slide(prs, '🔗 Ensemble Results', [
'🗳️ VOTING',
'• F1: 0.2446',
'',
'📊 AVG SCORES',
'• F1: 0.6459',
'• Recall: 99%'
], [
'⚖️ THRESHOLD',
'• F1: 0.4161',
'',
'🎯 STACKING',
'• F1: 0.0451'
])
add_content_slide(prs, '🔑 Key Findings', [
'✅ IF achieves 71% precision',
'⚖️ Critical precision-recall trade-off',
'🔧 Ensembles provide flexibility',
' • Voting: Conservative',
' • Avg: High sensitivity (99% recall)',
' • Threshold: Balanced'
])
add_content_slide(prs, '⚡ Performance', [
'🚀 TRAINING',
' • Total: ~20s | IF: 0.9s',
'',
'⚡ INFERENCE',
' • 0.8ms/sample (1,250/sec)',
'',
'💾 RESOURCES',
' • Memory: 450 MB',
' • Model: 285 KB | Total: <1 MB'
])
add_content_slide(prs, '🌐 REST API', [
'⚙️ FastAPI Service',
' • GET /health',
' • POST /predict',
'',
'📥 JSON input with auto-preprocessing',
'📤 Predictions + scores',
'🚀 Docker/Kubernetes ready'
])
add_two_column_slide(prs, '⚠️ Challenges & Solutions', [
'❌ LOF hanging',
'✅ Reduced neighbors to 10',
'',
'❌ Autoencoder froze',
'✅ IF+LOF baseline'
], [
'❌ Matplotlib delays',
'✅ Optimized plots',
'',
'❌ Encoding errors',
'✅ UTF-8 enforcement'
])
add_content_slide(prs, '🔴 Limitations', [
'⚠️ Low recall (≤15%)',
'⚠️ Single dataset (NSL-KDD 2009)',
'⚠️ Static models (no drift detection)',
'⚠️ Limited feature engineering'
])
add_content_slide(prs, '🔮 Future Work', [
'🔍 SHAP feature importance',
'🔄 K-fold cross-validation',
'🎯 Threshold optimization',
'📊 Multi-dataset evaluation',
'📡 Real-time drift detection',
'🧠 Deep learning with GPU',
'☁️ Kubernetes deployment',
'🔗 SIEM integration'
])
add_content_slide(prs, '✅ Conclusions', [
'🏆 Production-ready system built',
'',
'🎯 ACHIEVEMENTS',
' • IF: F1=0.2446, ROC=0.8476',
' • 4 ensemble strategies',
' • <1ms inference API',
' • 10 visualizations',
'',
'💡 Ready for deployment'
])
# Thank You slide
slide = prs.slides.add_slide(prs.slide_layouts[6])
add_dark_background(slide)
for i in range(0, 8):
line = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(i*1.25), 0, Inches(0.01), prs.slide_height)
line.fill.solid()
line.fill.fore_color.rgb = RGBColor(0, 50, 80)
line.line.fill.background()
thank_you_box = slide.shapes.add_textbox(Inches(0.5), Inches(2.5), Inches(9), Inches(1.5))
thank_you_frame = thank_you_box.text_frame
thank_you_frame.text = '🔒 THANK YOU!'
ty_p = thank_you_frame.paragraphs[0]
ty_p.font.size = Pt(56)
ty_p.font.bold = True
ty_p.font.color.rgb = CYBER_GREEN
ty_p.alignment = PP_ALIGN.CENTER
questions_box = slide.shapes.add_textbox(Inches(0.5), Inches(4.5), Inches(9), Inches(1))
questions_frame = questions_box.text_frame
questions_frame.text = 'QUESTIONS?'
q_p = questions_frame.paragraphs[0]
q_p.font.size = Pt(36)
q_p.font.color.rgb = CYBER_CYAN
q_p.alignment = PP_ALIGN.CENTER
prs.save('Anomaly_Detection_Dark_Cyber.pptx')
print('✅ Created Dark Cyber-Themed Presentation!')
print('📊 Total: 25 slides')
print('🖼️ Includes: 10 visualizations')