Fix regressor fit crash when sklearn output is globally set to pandas#72
Closed
devYRPauli wants to merge 1 commit into
Closed
Fix regressor fit crash when sklearn output is globally set to pandas#72devYRPauli wants to merge 1 commit into
devYRPauli wants to merge 1 commit into
Conversation
TabFMRegressor.fit scales the target with a StandardScaler and calls .flatten() on the result. When the user has set sklearn.set_config(transform_output="pandas") globally, fit_transform returns a DataFrame, which has no .flatten(), raising AttributeError (issue google-research#58). Pin the target scaler to numpy output with set_output(transform="default") so target scaling is unaffected by the global config.
devYRPauli
requested review from
abhidas,
erzel,
rajatsen91,
siriuz42,
tamannarayan and
weihaokong
as code owners
July 19, 2026 01:37
Contributor
|
Hi, I think this may overlap with #59. That PR also includes a regression test for the global pandas output configuration, which may be useful here. |
Contributor
Author
|
Thanks for pointing that out, and apologies for the duplicate - I should have checked the open PR list against #58 before sending this. You are right that #59 covers this: same fix in the same place (pinning the y scaler with set_output(transform="default") before fit_transform().flatten()), and it also carries the regression test under sklearn.config_context(transform_output="pandas"), which mine does not. Yours is both earlier and more complete, so there is nothing here worth a second review. Closing this in favor of #59. |
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.
Problem
TabFMRegressor.fitscales the regression target with aStandardScalerand then calls.flatten()on the transformed result. When a user hassklearn.set_config(transform_output="pandas")set globally (common in analysis notebooks),fit_transformreturns a pandasDataFrame, which has no.flatten()method, so fitting fails with:This is issue #58 (regression example not working).
Fix
Pin the target scaler to numpy output via
set_output(transform="default"), so target scaling is unaffected by the user's global sklearn output configuration.Note: only this site needs the change. The classifier's
CategoricalOrdinalEncoderpath is not affected (that encoder is never wrapped to pandas output), andinverse_transformcalls are never wrapped either, so no other sites required a fix.Testing
AttributeErroron the regressor fit path withtransform_output="pandas"before the change, and confirmedfitcompletes cleanly after it.classifier_and_regressor_testpass locally.