Skip to content

set classifier metadata#413

Open
sarptandoven wants to merge 2 commits into
stanfordmlgroup:masterfrom
sarptandoven:fix-ngbclassifier-sklearn-classes
Open

set classifier metadata#413
sarptandoven wants to merge 2 commits into
stanfordmlgroup:masterfrom
sarptandoven:fix-ngbclassifier-sklearn-classes

Conversation

@sarptandoven

Copy link
Copy Markdown
Contributor

summary

sets the sklearn classifier metadata that NGBClassifier was missing, so sklearn tooling can treat it as a classifier after fitting.

fixes #350.

what changed

  • make NGBClassifier inherit from ClassifierMixin
  • set classes_ during fit and first partial_fit
  • encode labels internally with LabelEncoder
  • decode predict and staged_predict back to the original labels
  • encode Y_val when validation data is passed
  • keep predict_proba aligned with classes_
  • add classifier regression coverage for sklearn compatibility

why

sklearn metrics/display helpers such as RocCurveDisplay.from_estimator and cross_val_score(..., scoring="roc_auc") expect fitted classifiers to expose classifier metadata, especially classes_.

without it, NGBClassifier can fit and predict, but fails in common sklearn evaluation paths.

validation

  • git diff --check
  • make lint
  • manual sklearn probe for issue 'NGBClassifier' object has no attribute 'classes_' #350, string labels, validation labels, partial_fit, multiclass labels, clone, and pickle round-trip
  • pytest tests/test_basic.py::test_classifier_sets_sklearn_classes_and_encodes_labels -q
  • pytest tests/test_basic.py -q
  • pytest -q
  • make test

@alejandroschuler alejandroschuler self-requested a review June 24, 2026 16:40
@ryan-wolbeck ryan-wolbeck self-requested a review June 26, 2026 03:32
@ryan-wolbeck

ryan-wolbeck commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the update. #407 has now merged into master, but this PR is still based on the pre-#407 commit, so GitHub’s diff is showing some stale overlap from #407 — specifically the NGBClassifier validation_fraction / early_stopping_rounds API changes.

Could you please rebase this branch onto latest master and force-push with lease?

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.

'NGBClassifier' object has no attribute 'classes_'

3 participants