Upload README.md with huggingface_hub
Browse files16 unmodified lines17181920212021232425222327282425262728293031323330343532363738353639404142433944454647484950515253545556575859603 unmodified lines64656667686970515271727374757677787980811 unmodified line83848560868788897 unmodified lines979899747510010110210310416 unmodified linesRandom Forest that estimates defect risk from 21 NASA/PROMISE code metrics.Part of a three-agent DevSecOps auditor (metrics → transformer → gatekeeper).
> For a Hugging Face repo, upload this file as `README.md` alongside> `agent1_rf.joblib` and `agent1_rf.meta.json`.## Model details
## Files
| File | Contents || Field | Value ||---|---|| `agent1_rf.joblib` | `model`, `raw_cols`, `feature_cols`, `threshold` || `agent1_rf.meta.json` | Dataset, seed, threshold, best params || Version | 1.0.0 (initial release) || Artifact | `model.joblib` (bundle: `model`, `raw_cols`, `feature_cols`, `threshold`) || Task | Binary tabular classification (defect / no defect) || Threshold | **0.3183** (tuned on training CV with F2) || Training data | NASA/PROMISE PC1 (`pc1.csv`) || Dataset version | Not pinned — static PC1 snapshot, no revision hash recorded || Seed | 42 |
`metadata.json` mirrors the dataset, threshold, and best params.
## Input## Input features
A row of 21 numeric metrics:21 numeric metrics:
```loc, vg, evg, ivg, n, v, l, d, i, e, b, t, locode, locomment,loccodeandcomment, loblank, uniq_op, uniq_opnd, total_op, total_opnd, branchcountloc, vg, evg, ivg, n, v, l, d, i, e, b, t,locode, locomment, loccodeandcomment, loblank,uniq_op, uniq_opnd, total_op, total_opnd, branchcount```
Five ratios are derived at inference time (already expected by `feature_cols`):Five derived features are added before prediction. Final `feature_cols` order(26 columns, must match exactly):
```loc, vg, evg, ivg, n, v, l, d, i, e, b, t,locode, locomment, loccodeandcomment, loblank,uniq_op, uniq_opnd, total_op, total_opnd, branchcount,complexity_density, effort_per_loc, comment_ratio, branch_density, operand_reuse```
## Preprocessing
- All 21 inputs must be numeric; no missing values (nothing is imputed).- Derive ratios with `+1` denominators:
```complexity_density = vg / (loc + 1)3 unmodified linesoperand_reuse = total_opnd / (uniq_opnd + 1)```
- Select `b["feature_cols"]` in the order above.
## Output
`predict_proba(X)[:, 1]` — defect risk in `[0, 1]`, uncalibrated.Decision threshold: **0.3183** (tuned on training CV with F2, recall-weighted).Raw: `predict_proba(X)[0, 1]` — defect risk in `[0, 1]`, uncalibrated.`high_risk = score >= 0.3183`.
Reference wrapper output:
```json{"struct_risk_score": 0.5105, "high_risk": true, "threshold": 0.3183, "status": "ok", "reason": ""}```
## Usage
1 unmodified lineimport joblibimport pandas as pd
b = joblib.load("agent1_rf.joblib")b = joblib.load("model.joblib")df = pd.DataFrame([metrics])[b["raw_cols"]].apply(pd.to_numeric)
df["complexity_density"] = df["vg"] / (df["loc"] + 1)7 unmodified lineshigh_risk = score >= b["threshold"]```
Trained on `data/pc1.csv` (NASA PROMISE). Metrics from other languages ordomains are out-of-distribution.Trained on NASA PROMISE PC1. Metrics from other languages or domains areout-of-distribution.
## License
README.md+43-17