Skip to content

fix(search): default to the classification task for a classifier - #115

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/77-search-classifier-task
Open

ChrisW09 wants to merge 1 commit into
mainfrom
fix/77-search-classifier-task

Conversation

@ChrisW09

@ChrisW09 ChrisW09 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #77.

RepresentationSearchCV around a classifier built every candidate Preprocessor with the default task="regression". Target-aware candidates ("ple", and the feature maps and splines that Preprocessor places on the target by default) crashed on string class labels, and they placed bins, centers and knots for integer labels with a regression model.

Root cause

RepresentationSearchCV already checks is_classifier(self.estimator) to choose a stratified splitter, but _make_preprocessor forwarded only random_state and preprocessor_params, so it never derived task from the estimator.

Fix

RepresentationSearchCV._make_preprocessor sets task="classification" with params.setdefault when the estimator is a classifier. A task given in preprocessor_params still takes precedence.

Behaviour changes

  • A search around a classifier fits its preprocessors with task="classification": string labels work, integer labels are placed by a classification model (DecisionTreeClassifier for "cart", LightGBM's classification objective for "lightgbm"), and best_preprocessor_.task is "classification". For binary 0/1 labels with "cart" placement the locations stay the same, as the issue explains. Multiclass labels and "lightgbm" placement can get different locations.
  • Searches around a regressor, and searches that set task in preprocessor_params, are unchanged.

Documentation

  • RepresentationSearchCV docstring (preprocessor_params): with a classifier as estimator, task defaults to "classification". The private _make_preprocessor docstring says the same.
  • docs/core_concepts/target_awareness.md ("Searching over representations"): with a classifier, every Preprocessor uses task="classification", so target-aware methods place against the class labels, and a task set in preprocessor_params takes precedence.

Tests

  • test_classifier_search_places_against_class_labels: a search around LogisticRegression on string labels with methods ["minmax", "ple"] fits, best_preprocessor_.task == "classification", and the predictions are class labels. Fails on main (could not convert string to float: np.str_('pos')), passes here.
  • test_classifier_search_keeps_an_explicit_task: preprocessor_params={"task": "regression"} overrides the classifier default. Guard test: passes on both by design.
  • test_regressor_search_keeps_the_regression_task: a search around a regressor keeps task="regression". Guard test: passes on both by design.

Reproduction

Output of the script from #77 on this branch:

string labels -> best_preprocessor_.task = classification
integer labels -> best_preprocessor_.task = classification

Checks

  • just test: 1441 passed, 59 skipped, 7 xfailed; coverage 93.65% (gate 90%).
  • Minimum dependencies (CI job: Python 3.10, numpy 1.24.4, pandas 2.0.3, scipy 1.10.1, scikit-learn 1.6.0): 1428 passed, 72 skipped, 7 xfailed; scripts/quickstart.py passes.
  • just docs: strict build succeeds.
  • just check: all pre-commit and pre-push hooks pass (ruff format, ruff lint, prettier, file hygiene, pyright with 0 errors).
  • Import direction between subpackages is unchanged.

Merge notes

This change was previously part of #86, which is closed in favour of one pull request per issue.

RepresentationSearchCV stratified its folds for a classifier but built every
candidate Preprocessor with the default task="regression". Target-aware
placement then crashed on string class labels and treated integer labels as a
regression target. A classifier now defaults the preprocessors to
task="classification"; an explicit task in preprocessor_params still wins.

Fixes #77

This branch has not been deployed

No deployments
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.

RepresentationSearchCV with a classifier uses task="regression" for placement; string labels crash

1 participant