Tabular Classification
Scikit-learn
English
logistic_regression
cybersecurity
security
logs
anomaly-detection
intrusion-detection
siem
mitre-attack
explainable-ai
logistic-regression
skops
Eval Results (legacy)
Instructions to use DaveyD347/log-anomaly-context-lr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use DaveyD347/log-anomaly-context-lr with Scikit-learn:
# ⚠️ Model filename not specified in config.json
- Notebooks
- Google Colab
- Kaggle
Download src/export_space.py from DaveyD347/log-anomaly-context-lr: direct link, hf CLI and curl.
- Browser
- Download file 3.06 kB
-
https://huggingface.co/DaveyD347/log-anomaly-context-lr/resolve/main/src/export_space.py
- Command line
-
hf download hf://DaveyD347/log-anomaly-context-lr/src/export_space.py
-
curl -L -o export_space.py https://huggingface.co/DaveyD347/log-anomaly-context-lr/resolve/main/src/export_space.py
3.06 kB
| """Copy the browser model into the Space and pick the sample streams it offers. | |
| Usage: python src/export_space.py --data ../incident-logs-dataset/data --challenge data/challenge.parquet | |
| """ | |
| import argparse | |
| import json | |
| import shutil | |
| import pandas as pd | |
| from common import load_events | |
| # (scenario, button label, source set) | |
| PICKS = [ | |
| ("ssh_bruteforce_persistence", "SSH brute force → cron persistence", "test"), | |
| ("web_sqli_webshell", "SQL injection → web shell", "test"), | |
| ("cloud_key_compromise", "Stolen AWS key", "test"), | |
| ("dns_tunneling_exfil", "DNS tunneling", "test"), | |
| ("credential_stuffing", "Credential stuffing", "test"), | |
| ("benign_ssh_admin", "Admins (typo'd passwords)", "test"), | |
| ("benign_cloud_ops", "Cloud ops (key rotation)", "test"), | |
| ("ch_ssh_spray", "Slow SSH spray + miner (unseen)", "challenge"), | |
| ("ch_cloud_key", "Stolen key, normal CLI (unseen)", "challenge"), | |
| ("ch_dns_tunnel", "Hex DNS tunnel (unseen)", "challenge"), | |
| ("ch_benign_web", "Health checks + typos (unseen)", "challenge"), | |
| ] | |
| MAX_LINES = 70 | |
| def pick(df, scenario, need_hard_negative=False): | |
| g = df[df.scenario == scenario] | |
| sizes = g.groupby("session_id").size() | |
| ok = sizes[(sizes >= 15) & (sizes <= MAX_LINES)] | |
| cands = list(ok.index) or list(sizes.sort_values().index[:1]) | |
| for sid in cands: | |
| s = g[g.session_id == sid] | |
| if scenario == "benign_ssh_admin" and not s.raw_log.str.contains("Failed password").any(): | |
| continue | |
| if scenario == "benign_cloud_ops" and not s.raw_log.str.contains("CreateAccessKey").any(): | |
| continue | |
| if scenario == "cloud_key_compromise" and not s.raw_log.str.contains("StopLogging|DeleteTrail").any(): | |
| continue | |
| if scenario == "web_sqli_webshell" and not s.raw_log.str.contains("/dev/tcp").any(): | |
| continue | |
| return s.sort_values("seq").head(MAX_LINES) | |
| return g[g.session_id == cands[0]].sort_values("seq").head(MAX_LINES) | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--data", default=None) | |
| ap.add_argument("--challenge", default="data/challenge.parquet") | |
| ap.add_argument("--model", default="outputs/model/model.json") | |
| ap.add_argument("--space", default="space") | |
| args = ap.parse_args() | |
| shutil.copy(args.model, f"{args.space}/model.json") | |
| sets = {"test": load_events(args.data, "test"), "challenge": pd.read_parquet(args.challenge)} | |
| out = [] | |
| for scen, label, src in PICKS: | |
| s = pick(sets[src], scen) | |
| out.append({"name": label, "set": src, "scenario": scen, | |
| "malicious": bool(s.is_malicious.any()), | |
| "lines": s.raw_log.tolist(), "truth": s.is_malicious.astype(int).tolist(), | |
| "technique": s.mitre_technique_id.fillna("").tolist()}) | |
| with open(f"{args.space}/samples.json", "w") as fh: | |
| json.dump(out, fh, separators=(",", ":")) | |
| print(f"wrote {len(out)} samples:", [(o["name"], len(o["lines"])) for o in out]) | |
| if __name__ == "__main__": | |
| main() | |