score_table8 v1.1.0: full paper-cell comparison; IoTProber vendor cells reproduce under exact match, B2 under fuzzy; B1 documented as not reproducible
Browse files
evaluation/unseen/score_table8.py
CHANGED
|
@@ -2,21 +2,40 @@
|
|
| 2 |
"""Table 8 (unseen devices: VPN / Media Server) canonical scorer.
|
| 3 |
|
| 4 |
Recomputes every Table 8 cell from the RAW released prediction artifacts
|
| 5 |
-
(no derived CSVs needed)
|
| 6 |
-
``split_and_evaluate.py`` (which stays the single source of truth — this
|
| 7 |
-
script imports its functions so the two can never drift):
|
| 8 |
|
| 9 |
type : accuracy = P(pred_type == device); F1 = 2*acc/(1+acc)
|
| 10 |
(binary positive-class F1 — every test IP is of the unseen type,
|
| 11 |
-
so precision is 1 by construction; see split_and_evaluate.py
|
|
|
|
| 12 |
vendor : top-1 / top-3 accuracy over the vendor-labeled subset
|
| 13 |
-
(evaluation/unseen/vendor/dataset/test_<dev>_label.csv)
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
Inputs (HuggingFace ``IoTProber/raw_dataset``, prefix ``evaluation/unseen``):
|
| 17 |
predict/IoTProber/predict_{dev}.json
|
| 18 |
-
predict/baseline/Mahmood/predict_{dev}.json
|
| 19 |
-
predict/baseline/ClaudeOpus/all_result_type_{dev}.csv
|
| 20 |
predict/baseline/llama3raw/all_result_type_{dev}.csv
|
| 21 |
|
| 22 |
Usage
|
|
@@ -30,7 +49,6 @@ import platform
|
|
| 30 |
import sys
|
| 31 |
|
| 32 |
import pandas as pd
|
| 33 |
-
import sklearn
|
| 34 |
|
| 35 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 36 |
from split_and_evaluate import ( # noqa: E402
|
|
@@ -41,18 +59,22 @@ from split_and_evaluate import ( # noqa: E402
|
|
| 41 |
compute_vendor_metrics,
|
| 42 |
)
|
| 43 |
|
| 44 |
-
SCORER_VERSION = "1.
|
| 45 |
|
| 46 |
-
# Paper (CCS'26 submission) Table 8 cells, format IoTProber / B1 / B2
|
|
|
|
| 47 |
PAPER_CELLS = {
|
| 48 |
-
# device: {metric: (IoTProber, B1, B2)}
|
| 49 |
"MEDIA_SERVER": {
|
| 50 |
"type_f1": ("0.9980", "0.8234", "0.7979"),
|
| 51 |
"type_accuracy": ("0.9961", "0.7512", "0.6638"),
|
|
|
|
|
|
|
| 52 |
},
|
| 53 |
"VPN": {
|
| 54 |
-
"type_f1": ("0.9963",
|
| 55 |
-
"type_accuracy": ("0.9926",
|
|
|
|
|
|
|
| 56 |
},
|
| 57 |
}
|
| 58 |
|
|
@@ -67,6 +89,19 @@ def type_metrics(type_df, dev):
|
|
| 67 |
return round(f1, 4), round(acc, 4)
|
| 68 |
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def main():
|
| 71 |
base = os.path.dirname(os.path.abspath(__file__))
|
| 72 |
ap = argparse.ArgumentParser()
|
|
@@ -77,14 +112,16 @@ def main():
|
|
| 77 |
"scorer_version": SCORER_VERSION,
|
| 78 |
"python": platform.python_version(),
|
| 79 |
"pandas": pd.__version__,
|
| 80 |
-
"
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
"rows": [],
|
| 84 |
}
|
| 85 |
|
| 86 |
header = (f"{'device':<14}{'method':<12}{'type F1':>9}{'type acc':>10}"
|
| 87 |
-
f"{'
|
| 88 |
lines = [header, "-" * len(header)]
|
| 89 |
for dev in DEVICE_TYPES:
|
| 90 |
ip2v = load_vendor_labels(dev)
|
|
@@ -99,29 +136,42 @@ def main():
|
|
| 99 |
else:
|
| 100 |
type_df, vendor_df = load_predictions_csv(dev, path)
|
| 101 |
f1, acc = type_metrics(type_df, dev)
|
| 102 |
-
|
|
|
|
| 103 |
row = {"device": dev, "method": m, "type_f1": f1, "type_accuracy": acc,
|
| 104 |
-
"
|
|
|
|
|
|
|
| 105 |
record["rows"].append(row)
|
| 106 |
-
lines.append(f"{dev:<14}{m:<12}{f1:>9}{acc:>10}
|
|
|
|
| 107 |
lines.append("")
|
| 108 |
|
| 109 |
-
lines.append("Paper Table 8 cells (IoTProber / B1 / B2) vs recomputed
|
|
|
|
| 110 |
for dev, metrics in PAPER_CELLS.items():
|
|
|
|
| 111 |
for metric, cells in metrics.items():
|
| 112 |
-
got = {}
|
| 113 |
-
for row in record["rows"]:
|
| 114 |
-
if row["device"] == dev:
|
| 115 |
-
got[row["method"]] = row[metric]
|
| 116 |
-
line = f" {dev:<14}{metric:<15}"
|
| 117 |
for i, m in enumerate(PAPER_METHOD_ORDER):
|
| 118 |
want = cells[i]
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
report = "\n".join(lines)
|
| 127 |
print(report)
|
|
|
|
| 2 |
"""Table 8 (unseen devices: VPN / Media Server) canonical scorer.
|
| 3 |
|
| 4 |
Recomputes every Table 8 cell from the RAW released prediction artifacts
|
| 5 |
+
(no derived CSVs needed) with EXPLICIT conventions:
|
|
|
|
|
|
|
| 6 |
|
| 7 |
type : accuracy = P(pred_type == device); F1 = 2*acc/(1+acc)
|
| 8 |
(binary positive-class F1 — every test IP is of the unseen type,
|
| 9 |
+
so precision is 1 by construction; see split_and_evaluate.py,
|
| 10 |
+
whose loader functions this script imports)
|
| 11 |
vendor : top-1 / top-3 accuracy over the vendor-labeled subset
|
| 12 |
+
(evaluation/unseen/vendor/dataset/test_<dev>_label.csv), reported
|
| 13 |
+
under BOTH conventions:
|
| 14 |
+
fuzzy case/punctuation-insensitive (split_and_evaluate canonical)
|
| 15 |
+
exact case-sensitive byte equality
|
| 16 |
+
|
| 17 |
+
Verified findings (scorer v1.1.0) — which convention reproduces the paper:
|
| 18 |
+
* IoTProber vendor cells reproduce under EXACT match only:
|
| 19 |
+
VPN 3572/3933 = 0.9082 (fuzzy would give 0.9090; the 3 flipped IPs are
|
| 20 |
+
case-only variants: SonicWall/SonicWALL ×2, TP-Link/TP-LINK),
|
| 21 |
+
MEDIA_SERVER 8932/9525 = 0.9377 (fuzzy 0.9378; one Asus/ASUS flip).
|
| 22 |
+
* B2 (ClaudeOpus) vendor cells reproduce under FUZZY match only
|
| 23 |
+
(exact drops them to 0.6272/0.9602 and 0.8411/0.8986).
|
| 24 |
+
=> the paper's Table 8 mixes two vendor-scoring passes.
|
| 25 |
+
* B2 type cells reproduce exactly (its released type_analysis.csv contains
|
| 26 |
+
0.7979/0.6638 and 0.1586/0.0861).
|
| 27 |
+
* B1 (Mahmood) cells are NOT reproducible from the released
|
| 28 |
+
predict_{dev}.json: they give type 0.7802/0.6397 (MS) and 0.7668/0.6217
|
| 29 |
+
(VPN), vendor 0.5630/0.9415 (MS) and 0.5645/0.9321 (VPN) under every
|
| 30 |
+
convention tested. The printed B1 values (0.8234/0.7512, 0.3421/0.2156,
|
| 31 |
+
0.5123/0.8456, 0.6234/0.8912) admit no integer solution at the released
|
| 32 |
+
denominators (7804/12050/3933/9525), so they come from a different B1
|
| 33 |
+
prediction matrix that was not preserved.
|
| 34 |
|
| 35 |
Inputs (HuggingFace ``IoTProber/raw_dataset``, prefix ``evaluation/unseen``):
|
| 36 |
predict/IoTProber/predict_{dev}.json
|
| 37 |
+
predict/baseline/Mahmood/predict_{dev}.json (B1)
|
| 38 |
+
predict/baseline/ClaudeOpus/all_result_type_{dev}.csv (B2)
|
| 39 |
predict/baseline/llama3raw/all_result_type_{dev}.csv
|
| 40 |
|
| 41 |
Usage
|
|
|
|
| 49 |
import sys
|
| 50 |
|
| 51 |
import pandas as pd
|
|
|
|
| 52 |
|
| 53 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 54 |
from split_and_evaluate import ( # noqa: E402
|
|
|
|
| 59 |
compute_vendor_metrics,
|
| 60 |
)
|
| 61 |
|
| 62 |
+
SCORER_VERSION = "1.1.0"
|
| 63 |
|
| 64 |
+
# Paper (CCS'26 submission) Table 8 cells, format IoTProber / B1 / B2
|
| 65 |
+
# (source: evaluation/unseen/table4.tex).
|
| 66 |
PAPER_CELLS = {
|
|
|
|
| 67 |
"MEDIA_SERVER": {
|
| 68 |
"type_f1": ("0.9980", "0.8234", "0.7979"),
|
| 69 |
"type_accuracy": ("0.9961", "0.7512", "0.6638"),
|
| 70 |
+
"vendor_top1": ("0.9377", "0.5123", "0.6299"),
|
| 71 |
+
"vendor_top3": ("1.0000", "0.8456", "0.9654"),
|
| 72 |
},
|
| 73 |
"VPN": {
|
| 74 |
+
"type_f1": ("0.9963", "0.3421", "0.1586"),
|
| 75 |
+
"type_accuracy": ("0.9926", "0.2156", "0.0861"),
|
| 76 |
+
"vendor_top1": ("0.9082", "0.6234", "0.8596"),
|
| 77 |
+
"vendor_top3": ("1.0000", "0.8912", "0.9186"),
|
| 78 |
},
|
| 79 |
}
|
| 80 |
|
|
|
|
| 89 |
return round(f1, 4), round(acc, 4)
|
| 90 |
|
| 91 |
|
| 92 |
+
def vendor_metrics_exact(vendor_df, ip2vendor):
|
| 93 |
+
"""Case-sensitive byte-equality top-1/top-3 over the labeled subset."""
|
| 94 |
+
df = vendor_df[vendor_df["ip"].isin(ip2vendor)].copy()
|
| 95 |
+
if df.empty:
|
| 96 |
+
return 0.0, 0.0
|
| 97 |
+
true = df["ip"].map(ip2vendor).astype(str)
|
| 98 |
+
tops = [df[c].astype(str) for c in ("pred_top1", "pred_top2", "pred_top3")]
|
| 99 |
+
n = len(df)
|
| 100 |
+
top1 = (true == tops[0]).sum() / n
|
| 101 |
+
top3 = ((true == tops[0]) | (true == tops[1]) | (true == tops[2])).sum() / n
|
| 102 |
+
return round(top1, 4), round(top3, 4)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
def main():
|
| 106 |
base = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
ap = argparse.ArgumentParser()
|
|
|
|
| 112 |
"scorer_version": SCORER_VERSION,
|
| 113 |
"python": platform.python_version(),
|
| 114 |
"pandas": pd.__version__,
|
| 115 |
+
"conventions": {
|
| 116 |
+
"type": "F1 = 2*acc/(1+acc), acc = P(pred_type == device)",
|
| 117 |
+
"vendor_fuzzy": "split_and_evaluate.normalize_vendor on both sides",
|
| 118 |
+
"vendor_exact": "case-sensitive byte equality",
|
| 119 |
+
},
|
| 120 |
"rows": [],
|
| 121 |
}
|
| 122 |
|
| 123 |
header = (f"{'device':<14}{'method':<12}{'type F1':>9}{'type acc':>10}"
|
| 124 |
+
f"{'v top1 fz':>10}{'v top1 ex':>10}{'v top3 fz':>10}{'v top3 ex':>10}")
|
| 125 |
lines = [header, "-" * len(header)]
|
| 126 |
for dev in DEVICE_TYPES:
|
| 127 |
ip2v = load_vendor_labels(dev)
|
|
|
|
| 136 |
else:
|
| 137 |
type_df, vendor_df = load_predictions_csv(dev, path)
|
| 138 |
f1, acc = type_metrics(type_df, dev)
|
| 139 |
+
t1f, t3f = compute_vendor_metrics(vendor_df, ip2v)
|
| 140 |
+
t1e, t3e = vendor_metrics_exact(vendor_df, ip2v)
|
| 141 |
row = {"device": dev, "method": m, "type_f1": f1, "type_accuracy": acc,
|
| 142 |
+
"vendor_top1_fuzzy": t1f, "vendor_top1_exact": t1e,
|
| 143 |
+
"vendor_top3_fuzzy": t3f, "vendor_top3_exact": t3e,
|
| 144 |
+
"n": len(type_df)}
|
| 145 |
record["rows"].append(row)
|
| 146 |
+
lines.append(f"{dev:<14}{m:<12}{f1:>9}{acc:>10}"
|
| 147 |
+
f"{t1f:>10}{t1e:>10}{t3f:>10}{t3e:>10}")
|
| 148 |
lines.append("")
|
| 149 |
|
| 150 |
+
lines.append("Paper Table 8 cells (IoTProber / B1 / B2) vs recomputed "
|
| 151 |
+
"(vendor: fz=comparison under fuzzy, ex=under exact):")
|
| 152 |
for dev, metrics in PAPER_CELLS.items():
|
| 153 |
+
got = {r["method"]: r for r in record["rows"] if r["device"] == dev}
|
| 154 |
for metric, cells in metrics.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
for i, m in enumerate(PAPER_METHOD_ORDER):
|
| 156 |
want = cells[i]
|
| 157 |
+
r = got.get(m)
|
| 158 |
+
if r is None:
|
| 159 |
+
continue
|
| 160 |
+
key = metric
|
| 161 |
+
if metric.startswith("vendor"):
|
| 162 |
+
key = metric # handled below with both conventions
|
| 163 |
+
have = r.get(key if key in r else metric)
|
| 164 |
+
if metric.startswith("vendor"):
|
| 165 |
+
fz = r[metric + "_fuzzy"] if metric + "_fuzzy" in r else r.get(metric)
|
| 166 |
+
ex = r[metric + "_exact"]
|
| 167 |
+
mark = ("OK(exact)" if f"{ex:.4f}" == want else
|
| 168 |
+
"OK(fuzzy)" if fz is not None and f"{fz:.4f}" == want else
|
| 169 |
+
f"DIFFERS (paper {want}; ex {ex}, fz {fz})")
|
| 170 |
+
lines.append(f" {dev:<14}{metric:<14}{m:<11}{mark}")
|
| 171 |
+
else:
|
| 172 |
+
mark = "OK" if have is not None and f"{have:.4f}" == want else \
|
| 173 |
+
f"DIFFERS (paper {want}, recomputed {have})"
|
| 174 |
+
lines.append(f" {dev:<14}{metric:<14}{m:<11}{mark}")
|
| 175 |
|
| 176 |
report = "\n".join(lines)
|
| 177 |
print(report)
|