Skip to content

Fix/multiclass prediction type safety#386

Merged
gbeane merged 3 commits into
feature/multiclassfrom
fix/multiclass-prediction-type-safety
Jun 2, 2026
Merged

Fix/multiclass prediction type safety#386
gbeane merged 3 commits into
feature/multiclassfrom
fix/multiclass-prediction-type-safety

Conversation

@gbeane
Copy link
Copy Markdown
Collaborator

@gbeane gbeane commented May 30, 2026

This pull request introduces improvements to how classifier settings are scoped by behavior and adds robust validation to prediction loading to prevent mismatches between binary and multi-class prediction records. It also updates the relevant tests to ensure correct behavior in these scenarios.

Classifier settings scoping improvements:

  • The Classifier.set_project_settings method now accepts an optional behavior argument, allowing explicit scoping of settings without relying on the classifier's behavior_name attribute. This makes the method more flexible and avoids previous ordering requirements. (src/jabs/classifier/classifier.py [1] src/jabs/classifier/cross_validation.py [2]
  • The MultiClassClassifier.set_project_settings method signature is updated for consistency, accepting a (unused) behavior argument to match the base class, simplifying interface usage. (src/jabs/classifier/multi_class_classifier.py src/jabs/classifier/multi_class_classifier.pyL121-R130)
  • Corresponding test cases are added to verify that explicitly provided behavior arguments are preferred over the attribute and that the correct project settings are loaded. (tests/classifier/test_classifier.py [1] tests/classifier/test_cross_validation.py [2]

Prediction loading validation:

  • The prediction manager now validates that the mode (binary vs multi-class) of loaded prediction records matches the caller's expectations. If a mismatch is detected, a ValueError is raised instead of silently returning mis-shaped data, preventing subtle bugs. (src/jabs/project/prediction_manager.py [1] [2] [3]
  • New tests ensure that attempts to load a multi-class record as binary (or vice versa) are correctly rejected with errors, rather than returning incorrect data. (tests/project/test_prediction_manager.py tests/project/test_prediction_manager.pyR231-R284)

@gbeane gbeane requested a review from Copilot May 30, 2026 03:18
@gbeane gbeane self-assigned this May 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves type safety around prediction loading by validating the binary/multi-class mode of stored records and refactors Classifier.set_project_settings to accept an explicit behavior argument, removing the prior requirement to set behavior_name first.

Changes:

  • Classifier.set_project_settings gains optional behavior arg; MultiClassClassifier mirrors the signature for parity; cross-validation now passes behavior explicitly.
  • PredictionManager._load_prediction_record requires keyword expect_multiclass and raises ValueError when the stored record's mode (presence of class_names) doesn't match.
  • New tests cover explicit-behavior precedence and cross-mode prediction rejection.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/jabs/classifier/classifier.py Accept optional behavior arg; prefer it over self._behavior when scoping settings.
src/jabs/classifier/multi_class_classifier.py Add unused behavior parameter for signature parity, with docstring.
src/jabs/classifier/cross_validation.py Pass behavior explicitly to set_project_settings and reorder relative to behavior_name assignment.
src/jabs/project/prediction_manager.py Add expect_multiclass keyword and raise ValueError on mode mismatch; expanded docstring.
tests/classifier/test_classifier.py New tests covering explicit behavior overriding/preferring over attribute.
tests/classifier/test_cross_validation.py Update fake classifier signature to match new set_project_settings.
tests/project/test_prediction_manager.py New tests verifying cross-mode reads raise ValueError.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ABS-behavior-classifier into fix/multiclass-prediction-type-safety

# Conflicts:
#	src/jabs/classifier/multi_class_classifier.py
@gbeane gbeane merged commit 45581f1 into feature/multiclass Jun 2, 2026
2 checks passed
@gbeane gbeane deleted the fix/multiclass-prediction-type-safety branch June 2, 2026 18:59
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.

3 participants