Skip to content

add json inference model serialization#415

Open
sarptandoven wants to merge 1 commit into
stanfordmlgroup:masterfrom
sarptandoven:add-json-inference-serialization
Open

add json inference model serialization#415
sarptandoven wants to merge 1 commit into
stanfordmlgroup:masterfrom
sarptandoven:add-json-inference-serialization

Conversation

@sarptandoven

Copy link
Copy Markdown
Contributor

summary

  • add save_ngboost_model_json and load_ngboost_model_json
  • serialize fitted default tree-based NGBoost models to JSON for inference without pickle
  • preserve regressor and classifier predictions across JSON round trips
  • document the new helpers in the README

change

  • encodes NGBoost model metadata, distribution/score, base learner config, init params, boosting state, and fitted sklearn decision tree state
  • reconstructs generated categorical classifier distributions via k_categorical(K)
  • stores sklearn tree structured arrays with explicit dtype names/formats/offsets/itemsize for exact reconstruction
  • adds regression coverage for NGBRegressor and NGBClassifier

why

Fixes #392 by providing a portable JSON model artifact for inference instead of requiring pickle/joblib for fitted models.

scope

This is an inference serialization path for fitted NGBoost models using DecisionTreeRegressor base learners. It does not try to be a full training-resume checkpoint format.

tests

  • poetry run pytest tests/test_pickling.py -q
  • poetry run pytest tests/test_basic.py -q
  • poetry run pytest tests/test_helpers.py tests/test_numpy2_compatibility.py tests/test_distns.py -q
  • poetry run pytest -q
  • poetry run pre-commit run --all-files

@alejandroschuler

Copy link
Copy Markdown
Collaborator

Thanks for the contribution @sarptandoven. The code seems correct but feels to me like this should be an issue we should handle with existing libraries as much as possible. I'm not sure if we need to be able to write to pure, "human-readable" json. So something like skops would likely be better and keep a smaller maintainable surface for ngboost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save model to json or universal binary json rather than pkl

2 participants