MhamedRayan commited on
Commit
00f3ba1
·
verified ·
1 Parent(s): 7b805a3

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +79 -0
README.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Agent 1 — Structural Risk (Random Forest)
2
+
3
+ Predicts defect risk from NASA/PROMISE code metrics. Trained on `data/pc1.csv`.
4
+ This model is a single artifact, so its README lives beside it as
5
+ `agent1_rf.README.md`.
6
+
7
+ ## Files
8
+
9
+ | File | Contents |
10
+ |---|---|
11
+ | `agent1_rf.joblib` | Model bundle: `model`, `raw_cols`, `feature_cols`, `threshold` |
12
+ | `agent1_rf.meta.json` | Human-readable copy: dataset, seed, threshold, best params |
13
+
14
+ Code: `agents/agent1_metrics.py`.
15
+
16
+ ## Input
17
+
18
+ One dict containing all 21 metrics:
19
+
20
+ ```
21
+ loc, vg, evg, ivg, n, v, l, d, i, e, b, t, locode, locomment,
22
+ loccodeandcomment, loblank, uniq_op, uniq_opnd, total_op, total_opnd, branchcount
23
+ ```
24
+
25
+ Keys are normalized (lowercased, stripped, parentheses removed), so `v(g)` and
26
+ `iv(G)` become `vg` and `ivg`. Values must be numeric. Five derived ratios
27
+ are computed internally (`complexity_density`, `effort_per_loc`, `comment_ratio`,
28
+ `branch_density`, `operand_reuse`) — do not supply them.
29
+
30
+ Missing keys or non-numeric values return an error; nothing is imputed at
31
+ inference time.
32
+
33
+ ## Output
34
+
35
+ Success:
36
+ ```json
37
+ {
38
+ "struct_risk_score": 0.5105,
39
+ "high_risk": true,
40
+ "threshold": 0.3183,
41
+ "status": "ok",
42
+ "reason": ""
43
+ }
44
+ ```
45
+
46
+ Error (note: no `threshold` key):
47
+ ```json
48
+ {
49
+ "struct_risk_score": null,
50
+ "high_risk": null,
51
+ "status": "error",
52
+ "reason": "missing features: ['loc', 'vg']"
53
+ }
54
+ ```
55
+
56
+ | Key | Success | Error |
57
+ |---|---|---|
58
+ | `struct_risk_score` | float 0–1 | `null` |
59
+ | `high_risk` | `score >= threshold` | `null` |
60
+ | `threshold` | `0.3183` | key absent |
61
+ | `status` | `"ok"` | `"error"` |
62
+ | `reason` | `""` | error detail |
63
+
64
+ `struct_risk_score` is an uncalibrated model score. `status != "ok"` means
65
+ Agent 3 will return `REVIEW`.
66
+
67
+ ## Usage
68
+
69
+ ```bash
70
+ # Train (needs data/pc1.csv)
71
+ python agents/agent1_metrics.py train --data data/pc1.csv
72
+
73
+ # Predict
74
+ python -c "from agents.agent1_metrics import predict_struct_risk; \
75
+ print(predict_struct_risk({'loc': 200, 'vg': 25, ...}))"
76
+
77
+ # Test
78
+ python test_agent1.py
79
+ ```