-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dataset_load.py
More file actions
48 lines (40 loc) · 1.66 KB
/
Copy pathtest_dataset_load.py
File metadata and controls
48 lines (40 loc) · 1.66 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
import csv
import os
from collections import Counter
def test_minimal_dataset():
dataset_path = os.path.join("data", "Z_ML_dataset.csv")
try:
with open(dataset_path, mode='r', encoding='latin-1') as file:
reader = csv.DictReader(file)
rows = list(reader)
if not rows:
print("Dataset is empty.")
return
print(f"Dataset loaded successfully with {len(rows)} entries.\n")
# Show column headers
print("🧾 Column Headers:")
print(" " + ", ".join(reader.fieldnames))
print("\n📄 Sample Entry:")
sample = rows[0]
for key, value in sample.items():
print(f" {key}: {value}")
# Count by label
label_counts = Counter(row["Label"].strip().lower() for row in rows)
print("\n📊 Entry Counts by Label:")
for label, count in label_counts.items():
emoji = {
"malicious": "🛑",
"suspicious": "⚠️",
"benign": "✅"
}.get(label, "❓")
print(f" {emoji} {label.capitalize()}: {count}")
except FileNotFoundError:
print("[❌] File not found. Please make sure 'Z_ML_dataset.csv' is in the 'data/' folder.")
except UnicodeDecodeError:
print("[❌] UnicodeDecodeError: File may not be saved in Latin-1 encoding.")
except KeyError:
print("[❌] Expected 'Prompt' and 'Label' columns not found.")
except Exception as e:
print(f"[❌] Unexpected error: {e}")
if __name__ == "__main__":
test_minimal_dataset()