File size: 2,504 Bytes
c4135cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
license: apache-2.0
tags:
  - cgm
  - time-series
  - glucose-forecasting
  - ridge-regression
  - metabonet
library_name: transformers
pipeline_tag: time-series-forecasting
---

# Ridge multi-horizon CGM forecaster (MetaboNet)

A `sklearn`-trained Ridge regressor (with `StandardScaler`) re-packaged as a
`transformers`-compatible Hub model. One repo holds four feature ablations
selectable at load time:

- `cgm` — 24 CGM lags + `hour_sin`/`hour_cos` (26 features).
- `insulin` — `cgm` features + 24 Insulin lags (50 features).
- `carbs` — `cgm` features + 24 Carbs lags (50 features).
- `all` — `cgm` features + 24 Insulin lags + 24 Carbs lags (74 features).

History length is 24 (= 2 hours at 5-minute sampling). Output is 12 future
CGM values (5–60 min horizons).

## Files

- `config.json` — `auto_map` wiring + per-ablation feature lists.
- `model.py` — `RidgeMultiHorizonConfig` / `RidgeMultiHorizonModel`
  (`trust_remote_code=True`).
- `model_<ablation>.safetensors` — one per ablation, holding `scaler_mean`,
  `scaler_scale`, `coef` (12 × F), `intercept` (12).

## Usage

```python
from transformers import AutoConfig, AutoModel

cfg = AutoConfig.from_pretrained(
    "anonymous-4FAD/Ridge", trust_remote_code=True, ablation="cgm"
)
model = AutoModel.from_pretrained(
    "anonymous-4FAD/Ridge", trust_remote_code=True, config=cfg
)

# Inputs match the MetaboNet benchmark.py contract:
#   timestamps: int64 ns, shape (B, T_in)
#   cgm/insulin/carbs: float, shape (B, T_in); only the last 24 steps are used
preds = model.predict(timestamps, cgm, insulin, carbs)  # -> (B, 12)
```

The thin local wrapper in
[`models/ridge.py`](https://github.com/njeffrie/MetaboNet-Bench/blob/main/models/ridge.py)
exposes the same API used by `benchmark.py`.

## Feature convention

`CGM_t<i>` denotes the i-th sample within the last `history_length` steps,
ordered oldest -> newest (`CGM_t0` is the oldest of the 24, `CGM_t23` is the
newest). The same convention applies to `Insulin_t<i>` and `Carbs_t<i>`.
`hour_sin` / `hour_cos` are derived from the most recent input timestamp.

## Provenance

Trained via
[`other_models/results/train_ridge.py`](https://github.com/njeffrie/MetaboNet-Bench/blob/main/other_models/results/train_ridge.py)
on the public MetaboNet train split. The `safetensors` checkpoints are produced
by [`scripts/build_other_models_hub.py`](https://github.com/njeffrie/MetaboNet-Bench/blob/main/scripts/build_other_models_hub.py)
from the original sklearn pickles.