Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -17,26 +17,44 @@ tags:
|
|
| 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 |
-
|
| 21 |
-
> `agent1_rf.joblib` and `agent1_rf.meta.json`.
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
| File | Contents |
|
| 26 |
|---|---|
|
| 27 |
-
|
|
| 28 |
-
| `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
## Input
|
| 31 |
|
| 32 |
-
|
| 33 |
|
| 34 |
```
|
| 35 |
-
loc, vg, evg, ivg, n, v, l, d, i, e, b, t,
|
| 36 |
-
|
|
|
|
| 37 |
```
|
| 38 |
|
| 39 |
-
Five
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
```
|
| 42 |
complexity_density = vg / (loc + 1)
|
|
@@ -46,10 +64,18 @@ branch_density = branchcount / (loc + 1)
|
|
| 46 |
operand_reuse = total_opnd / (uniq_opnd + 1)
|
| 47 |
```
|
| 48 |
|
|
|
|
|
|
|
| 49 |
## Output
|
| 50 |
|
| 51 |
-
`predict_proba(X)[
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
## Usage
|
| 55 |
|
|
@@ -57,7 +83,7 @@ Decision threshold: **0.3183** (tuned on training CV with F2, recall-weighted).
|
|
| 57 |
import joblib
|
| 58 |
import pandas as pd
|
| 59 |
|
| 60 |
-
b = joblib.load("
|
| 61 |
df = pd.DataFrame([metrics])[b["raw_cols"]].apply(pd.to_numeric)
|
| 62 |
|
| 63 |
df["complexity_density"] = df["vg"] / (df["loc"] + 1)
|
|
@@ -71,8 +97,8 @@ score = b["model"].predict_proba(X)[0, 1]
|
|
| 71 |
high_risk = score >= b["threshold"]
|
| 72 |
```
|
| 73 |
|
| 74 |
-
Trained on
|
| 75 |
-
|
| 76 |
|
| 77 |
## License
|
| 78 |
|
|
|
|
| 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 |
+
## Model details
|
|
|
|
| 21 |
|
| 22 |
+
| Field | Value |
|
|
|
|
|
|
|
| 23 |
|---|---|
|
| 24 |
+
| Version | 1.0.0 (initial release) |
|
| 25 |
+
| Artifact | `model.joblib` (bundle: `model`, `raw_cols`, `feature_cols`, `threshold`) |
|
| 26 |
+
| Task | Binary tabular classification (defect / no defect) |
|
| 27 |
+
| Threshold | **0.3183** (tuned on training CV with F2) |
|
| 28 |
+
| Training data | NASA/PROMISE PC1 (`pc1.csv`) |
|
| 29 |
+
| Dataset version | Not pinned — static PC1 snapshot, no revision hash recorded |
|
| 30 |
+
| Seed | 42 |
|
| 31 |
+
|
| 32 |
+
`metadata.json` mirrors the dataset, threshold, and best params.
|
| 33 |
|
| 34 |
+
## Input features
|
| 35 |
|
| 36 |
+
21 numeric metrics:
|
| 37 |
|
| 38 |
```
|
| 39 |
+
loc, vg, evg, ivg, n, v, l, d, i, e, b, t,
|
| 40 |
+
locode, locomment, loccodeandcomment, loblank,
|
| 41 |
+
uniq_op, uniq_opnd, total_op, total_opnd, branchcount
|
| 42 |
```
|
| 43 |
|
| 44 |
+
Five derived features are added before prediction. Final `feature_cols` order
|
| 45 |
+
(26 columns, must match exactly):
|
| 46 |
+
|
| 47 |
+
```
|
| 48 |
+
loc, vg, evg, ivg, n, v, l, d, i, e, b, t,
|
| 49 |
+
locode, locomment, loccodeandcomment, loblank,
|
| 50 |
+
uniq_op, uniq_opnd, total_op, total_opnd, branchcount,
|
| 51 |
+
complexity_density, effort_per_loc, comment_ratio, branch_density, operand_reuse
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## Preprocessing
|
| 55 |
+
|
| 56 |
+
- All 21 inputs must be numeric; no missing values (nothing is imputed).
|
| 57 |
+
- Derive ratios with `+1` denominators:
|
| 58 |
|
| 59 |
```
|
| 60 |
complexity_density = vg / (loc + 1)
|
|
|
|
| 64 |
operand_reuse = total_opnd / (uniq_opnd + 1)
|
| 65 |
```
|
| 66 |
|
| 67 |
+
- Select `b["feature_cols"]` in the order above.
|
| 68 |
+
|
| 69 |
## Output
|
| 70 |
|
| 71 |
+
Raw: `predict_proba(X)[0, 1]` — defect risk in `[0, 1]`, uncalibrated.
|
| 72 |
+
`high_risk = score >= 0.3183`.
|
| 73 |
+
|
| 74 |
+
Reference wrapper output:
|
| 75 |
+
|
| 76 |
+
```json
|
| 77 |
+
{"struct_risk_score": 0.5105, "high_risk": true, "threshold": 0.3183, "status": "ok", "reason": ""}
|
| 78 |
+
```
|
| 79 |
|
| 80 |
## Usage
|
| 81 |
|
|
|
|
| 83 |
import joblib
|
| 84 |
import pandas as pd
|
| 85 |
|
| 86 |
+
b = joblib.load("model.joblib")
|
| 87 |
df = pd.DataFrame([metrics])[b["raw_cols"]].apply(pd.to_numeric)
|
| 88 |
|
| 89 |
df["complexity_density"] = df["vg"] / (df["loc"] + 1)
|
|
|
|
| 97 |
high_risk = score >= b["threshold"]
|
| 98 |
```
|
| 99 |
|
| 100 |
+
Trained on NASA PROMISE PC1. Metrics from other languages or domains are
|
| 101 |
+
out-of-distribution.
|
| 102 |
|
| 103 |
## License
|
| 104 |
|