zebra-open 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zebra_open-0.1.0/LICENSE +109 -0
- zebra_open-0.1.0/PKG-INFO +447 -0
- zebra_open-0.1.0/README.md +321 -0
- zebra_open-0.1.0/pyproject.toml +35 -0
- zebra_open-0.1.0/setup.cfg +4 -0
- zebra_open-0.1.0/zebra_open/__init__.py +33 -0
- zebra_open-0.1.0/zebra_open/cli.py +225 -0
- zebra_open-0.1.0/zebra_open/cohort.py +174 -0
- zebra_open-0.1.0/zebra_open/examples/README.md +36 -0
- zebra_open-0.1.0/zebra_open/examples/quickstart.ipynb +281 -0
- zebra_open-0.1.0/zebra_open/generator.py +798 -0
- zebra_open-0.1.0/zebra_open/io.py +31 -0
- zebra_open-0.1.0/zebra_open/model.py +101 -0
- zebra_open-0.1.0/zebra_open/retro.py +1315 -0
- zebra_open-0.1.0/zebra_open.egg-info/PKG-INFO +447 -0
- zebra_open-0.1.0/zebra_open.egg-info/SOURCES.txt +18 -0
- zebra_open-0.1.0/zebra_open.egg-info/dependency_links.txt +1 -0
- zebra_open-0.1.0/zebra_open.egg-info/entry_points.txt +6 -0
- zebra_open-0.1.0/zebra_open.egg-info/requires.txt +8 -0
- zebra_open-0.1.0/zebra_open.egg-info/top_level.txt +1 -0
zebra_open-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship.
|
|
44
|
+
|
|
45
|
+
2. Grant of Copyright License.
|
|
46
|
+
|
|
47
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
48
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
49
|
+
royalty-free, irrevocable copyright license to reproduce, prepare
|
|
50
|
+
Derivative Works of, publicly display, publicly perform, sublicense,
|
|
51
|
+
and distribute the Work and such Derivative Works in Source or Object form.
|
|
52
|
+
|
|
53
|
+
3. Grant of Patent License.
|
|
54
|
+
|
|
55
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
56
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
57
|
+
royalty-free, irrevocable (except as stated in this section) patent
|
|
58
|
+
license to make, have made, use, offer to sell, sell, import, and
|
|
59
|
+
otherwise transfer the Work.
|
|
60
|
+
|
|
61
|
+
4. Redistribution.
|
|
62
|
+
|
|
63
|
+
You may reproduce and distribute copies of the Work or Derivative Works
|
|
64
|
+
thereof in any medium, with or without modifications, and in Source or
|
|
65
|
+
Object form, provided that You meet the following conditions:
|
|
66
|
+
|
|
67
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
68
|
+
a copy of this License; and
|
|
69
|
+
|
|
70
|
+
(b) You must cause any modified files to carry prominent notices stating
|
|
71
|
+
that You changed the files; and
|
|
72
|
+
|
|
73
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
74
|
+
distribute, all copyright, patent, trademark, and attribution notices
|
|
75
|
+
from the Source form of the Work.
|
|
76
|
+
|
|
77
|
+
5. Disclaimer of Warranty.
|
|
78
|
+
|
|
79
|
+
Unless required by applicable law or agreed to in writing, Licensor
|
|
80
|
+
provides the Work (and each Contributor provides its Contributions)
|
|
81
|
+
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
82
|
+
either express or implied, including, without limitation, any warranties
|
|
83
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS
|
|
84
|
+
FOR A PARTICULAR PURPOSE.
|
|
85
|
+
|
|
86
|
+
6. Limitation of Liability.
|
|
87
|
+
|
|
88
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
|
89
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
90
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor
|
|
91
|
+
be liable to You for damages, including any direct, indirect, special,
|
|
92
|
+
incidental, or consequential damages of any character arising as a result
|
|
93
|
+
of this License or out of the use or inability to use the Work.
|
|
94
|
+
|
|
95
|
+
END OF TERMS AND CONDITIONS
|
|
96
|
+
|
|
97
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
98
|
+
|
|
99
|
+
Copyright 2026 Ishanu Chattopadhyay
|
|
100
|
+
|
|
101
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
102
|
+
you may not use this file except in compliance with the License.
|
|
103
|
+
You may obtain a copy of the License at
|
|
104
|
+
|
|
105
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
106
|
+
|
|
107
|
+
Unless required by applicable law or agreed to in writing, software
|
|
108
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
109
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zebra-open
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Research-grade reference implementation of a ZeBRA-style retrospective risk modeling framework.
|
|
5
|
+
Author: Ishanu Chattopadhyay
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship.
|
|
49
|
+
|
|
50
|
+
2. Grant of Copyright License.
|
|
51
|
+
|
|
52
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
53
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
54
|
+
royalty-free, irrevocable copyright license to reproduce, prepare
|
|
55
|
+
Derivative Works of, publicly display, publicly perform, sublicense,
|
|
56
|
+
and distribute the Work and such Derivative Works in Source or Object form.
|
|
57
|
+
|
|
58
|
+
3. Grant of Patent License.
|
|
59
|
+
|
|
60
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
61
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
62
|
+
royalty-free, irrevocable (except as stated in this section) patent
|
|
63
|
+
license to make, have made, use, offer to sell, sell, import, and
|
|
64
|
+
otherwise transfer the Work.
|
|
65
|
+
|
|
66
|
+
4. Redistribution.
|
|
67
|
+
|
|
68
|
+
You may reproduce and distribute copies of the Work or Derivative Works
|
|
69
|
+
thereof in any medium, with or without modifications, and in Source or
|
|
70
|
+
Object form, provided that You meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
73
|
+
a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices stating
|
|
76
|
+
that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
79
|
+
distribute, all copyright, patent, trademark, and attribution notices
|
|
80
|
+
from the Source form of the Work.
|
|
81
|
+
|
|
82
|
+
5. Disclaimer of Warranty.
|
|
83
|
+
|
|
84
|
+
Unless required by applicable law or agreed to in writing, Licensor
|
|
85
|
+
provides the Work (and each Contributor provides its Contributions)
|
|
86
|
+
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
87
|
+
either express or implied, including, without limitation, any warranties
|
|
88
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS
|
|
89
|
+
FOR A PARTICULAR PURPOSE.
|
|
90
|
+
|
|
91
|
+
6. Limitation of Liability.
|
|
92
|
+
|
|
93
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
|
94
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
95
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor
|
|
96
|
+
be liable to You for damages, including any direct, indirect, special,
|
|
97
|
+
incidental, or consequential damages of any character arising as a result
|
|
98
|
+
of this License or out of the use or inability to use the Work.
|
|
99
|
+
|
|
100
|
+
END OF TERMS AND CONDITIONS
|
|
101
|
+
|
|
102
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
103
|
+
|
|
104
|
+
Copyright 2026 Ishanu Chattopadhyay
|
|
105
|
+
|
|
106
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
107
|
+
you may not use this file except in compliance with the License.
|
|
108
|
+
You may obtain a copy of the License at
|
|
109
|
+
|
|
110
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
111
|
+
|
|
112
|
+
Unless required by applicable law or agreed to in writing, software
|
|
113
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
114
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
115
|
+
|
|
116
|
+
Requires-Python: >=3.9
|
|
117
|
+
Description-Content-Type: text/markdown
|
|
118
|
+
License-File: LICENSE
|
|
119
|
+
Requires-Dist: numpy
|
|
120
|
+
Requires-Dist: pandas
|
|
121
|
+
Requires-Dist: scikit-learn
|
|
122
|
+
Requires-Dist: joblib
|
|
123
|
+
Requires-Dist: matplotlib
|
|
124
|
+
Requires-Dist: lightgbm; platform_system != "Emscripten"
|
|
125
|
+
Dynamic: license-file
|
|
126
|
+
|
|
127
|
+
# ZeBRA_open
|
|
128
|
+
|
|
129
|
+
ZeBRA_open is a research-grade implementation of a retrospective risk modeling framework based on the ZeBRA architecture. It is designed for methodological research in longitudinal health record modeling, temporally correct cohort construction, odds-ratio embeddings, and stacked prediction.
|
|
130
|
+
|
|
131
|
+
> **Research Use Only**
|
|
132
|
+
> This repository is not a medical device and must not be used for diagnosis, treatment, or clinical decision making. See `DISCLAIMER.md` and `CLINICAL_USE_NOTICE.md`.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
# Installation
|
|
137
|
+
|
|
138
|
+
From the ZeBRA_open repository root:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
python3 -m pip install -e ./python --no-cache-dir
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Alternatively:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
cd python
|
|
148
|
+
python3 -m pip install -e . --no-cache-dir
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Verify CLI availability:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
zebra-generate -h
|
|
155
|
+
zebra-cohort -h
|
|
156
|
+
zebra-train -h
|
|
157
|
+
zebra-eval -h
|
|
158
|
+
zebra-score -h
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
# Quickstart (CLI)
|
|
164
|
+
|
|
165
|
+
## 1) Generate Synthetic Cohort
|
|
166
|
+
|
|
167
|
+
Basic generation (DX-only JSONL cohort):
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
zebra-generate --out_dir data/generated/j8411_seed0 --n_patients 10000 --target J84.11 --case_frac 0.10 --seed 0 --start_date 2010-01-01 --end_date 2024-12-31
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Generator controls that mirror the standalone scripts:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
zebra-generate --out_dir data/generated/j8411_seed0_v2 --n_patients 10000 --target J84.11 --case_frac 0.10 --seed 1 --start_date 2010-01-01 --end_date 2024-12-31 --min_encounters_per_year 2 --max_encounters_per_year 14 --min_problem_list 2 --max_problem_list 18 --min_days_to_target 30 --max_days_to_target 2000 --target_min_occ 1 --target_max_occ 5 --target_last_third --missingness_encounter_drop 0.05 --missingness_code_drop 0.10
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Optional: enable the private LLM enrichment pack (OpenAI Responses API). This is disabled by default and must be explicitly turned on:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
export OPENAI_API_KEY="..."
|
|
183
|
+
zebra-generate --out_dir data/generated/j8411_seed0_llm --n_patients 2000 --target J84.11 --case_frac 0.10 --seed 2 --start_date 2010-01-01 --end_date 2024-12-31 --enable_private_llm_pack --openai_model gpt-5-nano --openai_timeout_s 45 --openai_max_output_tokens 1200
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Outputs:
|
|
187
|
+
|
|
188
|
+
- `patients.jsonl`
|
|
189
|
+
- `cohort_manifest.json`
|
|
190
|
+
|
|
191
|
+
Notes:
|
|
192
|
+
|
|
193
|
+
- The generator simulates utilization (encounters per year), per-patient observation span, and per-encounter code sampling.
|
|
194
|
+
- Missingness can be applied both at the encounter level (dropping encounters) and within encounters (dropping codes).
|
|
195
|
+
- The target code is inserted for cases with controls on placement and repetition.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 2) Summarize Cohort
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
zebra-cohort --patients data/generated/j8411_seed0/patients.jsonl --target_prefix J84.11 --out results/cohort_summary_j8411.csv --aggregate_json results/cohort_summary_j8411_agg.json
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 3) Train Retrospective Model
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
zebra-train --patients data/generated/j8411_seed0/patients.jsonl --target J84.11 --out results/zebra_j8411_v1 --observation_days 730 --horizon_days 28 --prediction_days 365 --confidence_days 365 --or_infer_frac 0.8 --val_frac 0.34 --random_state 0
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Primary artifact:
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
results/zebra_j8411_v1/zebra_retro_model.joblib
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## 4) Retrospective Evaluation (AUC + Calibration)
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
zebra-eval --model results/zebra_j8411_v1/zebra_retro_model.joblib --patients data/generated/j8411_seed0/patients.jsonl --out results/zebra_j8411_v1/eval.csv --summary results/zebra_j8411_v1/eval_summary.json --calibration_bins 10 --calibration_csv results/zebra_j8411_v1/calibration.csv --calibration_plot results/zebra_j8411_v1/calibration.png
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 5) Prospective Scoring
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
zebra-score --model results/zebra_j8411_v1/zebra_retro_model.joblib --patients data/generated/j8411_seed0/patients.jsonl --out results/zebra_j8411_v1/scores.csv --as_of 2023-12-31
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
If `--as_of` is omitted, scoring uses each patient's last observed event date.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
# Python API Quickstart
|
|
240
|
+
|
|
241
|
+
## Generate Cohort
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
from zebra_open.generator import (
|
|
245
|
+
GenParams,
|
|
246
|
+
generate_dx_cohort,
|
|
247
|
+
write_patients_jsonl,
|
|
248
|
+
write_manifest,
|
|
249
|
+
parse_yyyy_mm_dd,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
params = GenParams(
|
|
253
|
+
n_patients=10000,
|
|
254
|
+
case_frac=0.10,
|
|
255
|
+
target_code="J84.11",
|
|
256
|
+
start_date=parse_yyyy_mm_dd("2010-01-01"),
|
|
257
|
+
end_date=parse_yyyy_mm_dd("2024-12-31"),
|
|
258
|
+
seed=0,
|
|
259
|
+
output="data/generated/j8411_seed0",
|
|
260
|
+
jsonl=True,
|
|
261
|
+
target_min_occurrences=1,
|
|
262
|
+
target_max_occurrences=4,
|
|
263
|
+
target_last_third=True,
|
|
264
|
+
missingness_encounter_drop=0.05,
|
|
265
|
+
missingness_code_drop=0.10,
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
patients, manifest = generate_dx_cohort(
|
|
269
|
+
params,
|
|
270
|
+
enable_openai_pack=False,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
write_patients_jsonl(patients, "data/generated/j8411_seed0/patients.jsonl")
|
|
274
|
+
write_manifest(manifest, "data/generated/j8411_seed0/cohort_manifest.json")
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
If you want the OpenAI enrichment pack:
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
patients, manifest = generate_dx_cohort(
|
|
281
|
+
params,
|
|
282
|
+
enable_openai_pack=True,
|
|
283
|
+
openai_model="gpt-5-nano",
|
|
284
|
+
openai_timeout_s=45,
|
|
285
|
+
openai_max_output_tokens=1200,
|
|
286
|
+
)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Summarize Cohort
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from zebra_open.cohort import summarize_file, summarize_aggregate
|
|
295
|
+
|
|
296
|
+
df = summarize_file(
|
|
297
|
+
"data/generated/j8411_seed0/patients.jsonl",
|
|
298
|
+
target_prefix="J84.11",
|
|
299
|
+
out_path="results/cohort_summary_j8411.csv",
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
print(summarize_aggregate(df))
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Train Model
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
from zebra_open import ZebraModel
|
|
311
|
+
|
|
312
|
+
model = ZebraModel.from_config(
|
|
313
|
+
observation_days=730,
|
|
314
|
+
horizon_days=28,
|
|
315
|
+
prediction_days=365,
|
|
316
|
+
confidence_days=365,
|
|
317
|
+
or_infer_frac=0.8,
|
|
318
|
+
val_frac=0.34,
|
|
319
|
+
random_state=0,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
model.fit(
|
|
323
|
+
patients_json="data/generated/j8411_seed0/patients.jsonl",
|
|
324
|
+
target_codes=["J84.11"],
|
|
325
|
+
out_dir="results/zebra_j8411_v1",
|
|
326
|
+
)
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
# Input Format
|
|
332
|
+
|
|
333
|
+
Accepted formats:
|
|
334
|
+
|
|
335
|
+
- JSONL (one patient per line)
|
|
336
|
+
- JSON (list of patient objects)
|
|
337
|
+
|
|
338
|
+
Each patient must include one of:
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
patient_id
|
|
342
|
+
pid
|
|
343
|
+
id
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
DX records must follow:
|
|
347
|
+
|
|
348
|
+
```json
|
|
349
|
+
{
|
|
350
|
+
"date": "MM/DD/YYYY",
|
|
351
|
+
"code": "J84.11"
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
# Detailed CLI Option Reference
|
|
358
|
+
|
|
359
|
+
## zebra-generate
|
|
360
|
+
|
|
361
|
+
| Option | Description |
|
|
362
|
+
|--------|-------------|
|
|
363
|
+
| `--out_dir` | Output directory |
|
|
364
|
+
| `--n_patients` | Total patients |
|
|
365
|
+
| `--target` | ICD code |
|
|
366
|
+
| `--case_frac` | Fraction of cases |
|
|
367
|
+
| `--seed` | Random seed |
|
|
368
|
+
| `--start_date` | YYYY-MM-DD |
|
|
369
|
+
| `--end_date` | YYYY-MM-DD |
|
|
370
|
+
| `--min_encounters_per_year` | Utilization lower bound |
|
|
371
|
+
| `--max_encounters_per_year` | Utilization upper bound |
|
|
372
|
+
| `--min_problem_list` | Min chronic codes |
|
|
373
|
+
| `--max_problem_list` | Max chronic codes |
|
|
374
|
+
| `--min_days_to_target` | Target placement min (days from start) |
|
|
375
|
+
| `--max_days_to_target` | Target placement max (days from start) |
|
|
376
|
+
| `--target_min_occ` | Minimum number of target insertions for cases |
|
|
377
|
+
| `--target_max_occ` | Maximum number of target insertions for cases |
|
|
378
|
+
| `--target_last_third` | If set, force target occurrences into the final third of the timeline |
|
|
379
|
+
| `--missingness_encounter_drop` | Probability of dropping an encounter (0 to 1) |
|
|
380
|
+
| `--missingness_code_drop` | Probability of dropping a code within an encounter (0 to 1) |
|
|
381
|
+
| `--enable_private_llm_pack` | Enable OpenAI enrichment pack (disabled by default) |
|
|
382
|
+
| `--openai_model` | OpenAI model name (used only with private pack) |
|
|
383
|
+
| `--openai_timeout_s` | OpenAI request timeout seconds |
|
|
384
|
+
| `--openai_max_output_tokens` | Cap on OpenAI output tokens |
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## zebra-cohort
|
|
389
|
+
|
|
390
|
+
| Option | Description |
|
|
391
|
+
|--------|-------------|
|
|
392
|
+
| `--patients` | Patient file |
|
|
393
|
+
| `--target_prefix` | ICD prefix match |
|
|
394
|
+
| `--out` | Summary CSV/Parquet |
|
|
395
|
+
| `--aggregate_json` | Aggregate stats JSON |
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## zebra-train
|
|
400
|
+
|
|
401
|
+
| Option | Description |
|
|
402
|
+
|--------|-------------|
|
|
403
|
+
| `--patients` | Input patient file |
|
|
404
|
+
| `--target` | ICD code(s) |
|
|
405
|
+
| `--out` | Output directory |
|
|
406
|
+
| `--observation_days` | Feature lookback window |
|
|
407
|
+
| `--horizon_days` | Gap before prediction window |
|
|
408
|
+
| `--prediction_days` | Event window defining case |
|
|
409
|
+
| `--confidence_days` | Required control follow-up |
|
|
410
|
+
| `--or_infer_frac` | OR embedding split |
|
|
411
|
+
| `--val_frac` | Validation split |
|
|
412
|
+
| `--random_state` | Random seed |
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## zebra-eval
|
|
417
|
+
|
|
418
|
+
| Option | Description |
|
|
419
|
+
|--------|-------------|
|
|
420
|
+
| `--model` | Path to model |
|
|
421
|
+
| `--patients` | Patient file |
|
|
422
|
+
| `--out` | Eval CSV |
|
|
423
|
+
| `--summary` | JSON summary |
|
|
424
|
+
| `--calibration_bins` | Number of bins |
|
|
425
|
+
| `--calibration_csv` | Calibration CSV |
|
|
426
|
+
| `--calibration_plot` | Calibration PNG |
|
|
427
|
+
| `--target` | Override target |
|
|
428
|
+
| `--max_controls` | Control cap |
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
## zebra-score
|
|
433
|
+
|
|
434
|
+
| Option | Description |
|
|
435
|
+
|--------|-------------|
|
|
436
|
+
| `--model` | Path to model |
|
|
437
|
+
| `--patients` | Patient file |
|
|
438
|
+
| `--out` | Scores CSV |
|
|
439
|
+
| `--as_of` | YYYY-MM-DD cut date |
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
# Notes
|
|
444
|
+
|
|
445
|
+
- Training and evaluation use identical temporal window logic.
|
|
446
|
+
- Prospective scoring performs feature construction at an as-of time without labeling.
|
|
447
|
+
- See `METHODS.md` for full algorithmic details.
|