MhamedRayan commited on
Commit
6f766a1
·
verified ·
1 Parent(s): 71d3a93

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +43 -17
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
- > 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)
@@ -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)[:, 1]` — defect risk in `[0, 1]`, uncalibrated.
52
- Decision threshold: **0.3183** (tuned on training CV with F2, recall-weighted).
 
 
 
 
 
 
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("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)
@@ -71,8 +97,8 @@ 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
 
 
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