Fix calibrator pickle compatibility and add clean inference API#16
Open
michaelzenkay wants to merge 2 commits intoyala:masterfrom
Open
Fix calibrator pickle compatibility and add clean inference API#16michaelzenkay wants to merge 2 commits intoyala:masterfrom
michaelzenkay wants to merge 2 commits intoyala:masterfrom
Conversation
- Fix calibrator loading across sklearn versions (0.20 -> 1.7+) by patching renamed internal attributes (calibrators/calibrators_, classes/classes_, base_estimator/estimator) at load time - Add `scripts/infer.py` with a clean `predict()` function for programmatic inference without sys.argv manipulation. Auto-detects model files in a directory and returns a pandas DataFrame with calibrated risk scores. - Extract `run()` function from `scripts/main.py` so it can be called programmatically (previously all logic was in `if __name__ == '__main__'`) - Make `import git` optional (try/except) so the code works in environments without GitPython installed - Add `weights_only=False` to `torch.load` in model factory for PyTorch 2.6+ compatibility - Update README with sklearn compatibility note and inference API docs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CalibratedClassifierCVpickle loading across sklearn versions (0.20 → 1.7+) by patching renamed internal attributes (calibrators→calibrators_,classes→classes_,base_estimator→estimator)scripts/infer.py— a clean programmatic API (predict()) that builds args internally instead of requiringsys.argvmanipulationtorch.loadfor PyTorch 2.6+ (weights_only=False)Details
Calibrator compatibility (
scripts/main.py)Calibrator pickles saved with older sklearn versions fail on newer versions due to renamed internals:
ModuleNotFoundError: sklearn.svm.classes_CalibratedClassifiermissingcalibratorsattrCalibratedClassifierCVmissingestimatorattrAdded
_patch_calibrator()to fix attribute names after loading, andload_calibrator()with graceful error handling.Clean inference API (
scripts/infer.py)New programmatic interface that avoids
sys.argvmanipulation:PyTorch 2.6+ compatibility (
onconet/models/factory.py)Added
weights_only=Falsetotorch.loadcalls since PyTorch 2.6 changed the default toTrue.Test plan
predict_probaworksinfer.predict()on single exam, verify calibrated outputscripts/main.pyend-to-end, verify CSV export with calibrated scores