Spaces:
Running on Zero

File size: 1,129 Bytes
755f67e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Extract per-record features for all 552 records -> data/features.csv.

Feature extraction is a fixed, per-record transform with no fitted parameters, so computing it for
held-out records does not leak information. Nothing here looks at labels.
"""
import sys
from pathlib import Path

import pandas as pd

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from ctg.data import ROOT, load_clinical, load_signals, record_ids  # noqa: E402
from ctg.features import analyse  # noqa: E402
from ctg.signal import prepare_window  # noqa: E402


def main():
    rows = []
    for i, rid in enumerate(record_ids()):
        fhr, uc = load_signals(rid)
        a = analyse(prepare_window(fhr, uc))
        rows.append({"record": rid, **a.features})
        if (i + 1) % 100 == 0:
            print(f"{i + 1} records", flush=True)
    feats = pd.DataFrame(rows).set_index("record")
    clin = load_clinical()[["ph", "y_primary", "y_secondary", "caesarean"]]
    out = clin.join(feats)
    out.to_csv(ROOT / "data" / "features.csv")
    print(f"wrote data/features.csv: {out.shape}")


if __name__ == "__main__":
    main()