Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
library_name: scikit-learn
|
| 4 |
+
pipeline_tag: tabular-classification
|
| 5 |
+
tags:
|
| 6 |
+
- cybersecurity
|
| 7 |
+
- vulnerability-detection
|
| 8 |
+
- defect-prediction
|
| 9 |
+
- random-forest
|
| 10 |
+
- scikit-learn
|
| 11 |
+
- joblib
|
| 12 |
+
- nasa-promise
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Agent 1 — Structural Risk Random Forest
|
| 16 |
+
|
| 17 |
+
Random Forest that estimates defect risk from 21 NASA/PROMISE code metrics.
|
| 18 |
+
Part of a three-agent DevSecOps auditor (metrics → transformer → gatekeeper).
|
| 19 |
+
|
| 20 |
+
> For a Hugging Face repo, upload this file as `README.md` alongside
|
| 21 |
+
> `agent1_rf.joblib` and `agent1_rf.meta.json`.
|
| 22 |
+
|
| 23 |
+
## Files
|
| 24 |
+
|
| 25 |
+
| File | Contents |
|
| 26 |
+
|---|---|
|
| 27 |
+
| `agent1_rf.joblib` | `model`, `raw_cols`, `feature_cols`, `threshold` |
|
| 28 |
+
| `agent1_rf.meta.json` | Dataset, seed, threshold, best params |
|
| 29 |
+
|
| 30 |
+
## Input
|
| 31 |
+
|
| 32 |
+
A row of 21 numeric metrics:
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
loc, vg, evg, ivg, n, v, l, d, i, e, b, t, locode, locomment,
|
| 36 |
+
loccodeandcomment, loblank, uniq_op, uniq_opnd, total_op, total_opnd, branchcount
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Five ratios are derived at inference time (already expected by `feature_cols`):
|
| 40 |
+
|
| 41 |
+
```
|
| 42 |
+
complexity_density = vg / (loc + 1)
|
| 43 |
+
effort_per_loc = e / (loc + 1)
|
| 44 |
+
comment_ratio = locomment / (loc + 1)
|
| 45 |
+
branch_density = branchcount / (loc + 1)
|
| 46 |
+
operand_reuse = total_opnd / (uniq_opnd + 1)
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## Output
|
| 50 |
+
|
| 51 |
+
`predict_proba(X)[:, 1]` — defect risk in `[0, 1]`, uncalibrated.
|
| 52 |
+
Decision threshold: **0.3183** (tuned on training CV with F2, recall-weighted).
|
| 53 |
+
|
| 54 |
+
## Usage
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
import joblib
|
| 58 |
+
import pandas as pd
|
| 59 |
+
|
| 60 |
+
b = joblib.load("agent1_rf.joblib")
|
| 61 |
+
df = pd.DataFrame([metrics])[b["raw_cols"]].apply(pd.to_numeric)
|
| 62 |
+
|
| 63 |
+
df["complexity_density"] = df["vg"] / (df["loc"] + 1)
|
| 64 |
+
df["effort_per_loc"] = df["e"] / (df["loc"] + 1)
|
| 65 |
+
df["comment_ratio"] = df["locomment"] / (df["loc"] + 1)
|
| 66 |
+
df["branch_density"] = df["branchcount"] / (df["loc"] + 1)
|
| 67 |
+
df["operand_reuse"] = df["total_opnd"] / (df["uniq_opnd"] + 1)
|
| 68 |
+
|
| 69 |
+
X = df[b["feature_cols"]]
|
| 70 |
+
score = b["model"].predict_proba(X)[0, 1]
|
| 71 |
+
high_risk = score >= b["threshold"]
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
Trained on `data/pc1.csv` (NASA PROMISE). Metrics from other languages or
|
| 75 |
+
domains are out-of-distribution.
|
| 76 |
+
|
| 77 |
+
## License
|
| 78 |
+
|
| 79 |
+
Not specified. Update the `license` field before publishing.
|