cosanlab / cosanlab/nltools

Persist the fitted estimator so an expensive ridge fit can predict in a later session

Open
#534 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
130
Forks
48
Avg merge
6h 42m
Merged PRs (30d)
34

Description

Follow-up to #531. `BrainData.write('.h5')` on a fitted object stores the `FitResult` maps, design and kind, so a reload restores `data.model` and effect-only contrasts and the no-argument `predict()` work; `compute_contrasts(inference=True)`, `predict(X=...)` and `bootstrap` raise on a reloaded record with the one-line refit, and a ridge record's `cv` is not stored. The point where the estimator would be written is marked with a comment in `nltools/io/h5.py`.

Wanted, not blocking: optionally persist the fitted estimator (Himalaya ridge weights and selected alphas are plain arrays; nilearn's GLM regression results are heavier and noise-model dependent) so an expensive fit does not have to be re-estimated for prediction in a future session. Decide the storage format per model kind, what `write()` on the record should emit for it, and how a partial reload (maps without estimator) is reported to the user.

Contributor guide

Open the contributing guide

Research direction

Start in nltools/io/h5.py at the comment marking where the estimator would be written, then trace BrainData.write('.h5') and the existing FitResult reload path. Compare the ridge and nilearn GLM model kinds and determine what each should persist, including behavior when maps exist without an estimator. Done means a reloaded fitted record can use the supported prediction paths without unnecessary refitting and reports partial reloads clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data, machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.