nicholpt's picture
System One fraud detector for FDB ipblock, v1.0.0
697cf75 verified
Raw History Blame Contribute Delete
982 Bytes
#!/usr/bin/env python3
"""Score the first FDB test rows with the released pipeline: python examples/quickstart.py [n]
Needs the FDB package, and Kaggle API credentials for the Kaggle-hosted sets (see system_one_fraud/fdb.py).
"""
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from system_one_fraud import FraudPipeline # noqa: E402
from system_one_fraud.fdb import load_split # noqa: E402
n = int(sys.argv[1]) if len(sys.argv) > 1 else 8
key = json.loads((ROOT / "release.json").read_text())["set"]
_, test, _ = load_split(key)
rows = test.head(n)
pipe = FraudPipeline.from_pretrained(ROOT)
states, _ = pipe.states(rows)
print("System One evidence for the first row:")
print(json.dumps(states[0], indent=1, ensure_ascii=False))
ids = rows["EVENT_ID"] if "EVENT_ID" in rows.columns else rows.index
for event_id, p in zip(ids, pipe.predict_proba(rows)):
print(f"{event_id} probability = {p:.4f}")