10000 ColumnTransformer FunctionTransformer get_feature_names_out() does not work · Issue #23226 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

ColumnTransformer FunctionTransformer get_feature_names_out() does not work #23226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nilslacroix opened this issue Apr 27, 2022 · 2 comments
Closed
Labels
Bug Needs Triage Issue requires triage

Comments

@nilslacroix
Copy link
nilslacroix commented Apr 27, 2022

Describe the bug

When I use a FunctionTransformer in my ColumnTransformer and try to use the columntransformer.get_feature_names_out() function I get an error. Fitting/Predicting works fine as long as I dont touch this function.

Error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 3>()
      1 xt = preprocessor.transform(X_test)
      2 #mapie.single_estimator_[1].estimator
----> 3 preprocessor.get_feature_names_out()

File ~\miniconda3\envs\Master_ML\lib\site-packages\sklearn\compose\_column_transformer.py:481, in ColumnTransformer.get_feature_names_out(self, input_features)
    479 transformer_with_feature_names_out = []
    480 for name, trans, column, _ in self._iter(fitted=True):
--> 481     feature_names_out = self._get_feature_name_out_for_transformer(
    482         name, trans, column, input_features
    483     )
    484     if feature_names_out is None:
    485         continue

File ~\miniconda3\envs\Master_ML\lib\site-packages\sklearn\compose\_column_transformer.py:446, in ColumnTransformer._get_feature_name_out_for_transformer(self, name, trans, column, feature_names_in)
    444 # An actual transformer
    445 if not hasattr(trans, "get_feature_names_out"):
--> 446     raise AttributeError(
    447         f"Transformer {name} (type {type(trans).__name__}) does "
    448         "not provide get_feature_names_out."
    449     )
    450 if isinstance(column, Iterable) and not all(
    451     isinstance(col, str) for col in column
    452 ):
    453     column = _safe_indexing(feature_names_in, column)

AttributeError: Transformer log (type FunctionTransformer) does not provide get_feature_names_out.

Steps/Code to Reproduce

preprocessor = ColumnTransformer(
    transformers=
    [  
        ('log', FunctionTransformer(np.log1p, validate=True), log_features)
    ])

Fit on some estimator. Then print function:

xt = preprocessor.transform(X_test)
preprocessor.get_feature_names_out()

Gets the error as described above

Expected Results

Expected results are column names of cause.

Actual Results

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 3>()
      1 xt = preprocessor.transform(X_test)
      2 #mapie.single_estimator_[1].estimator
----> 3 preprocessor.get_feature_names_out()

File ~\miniconda3\envs\Master_ML\lib\site-packages\sklearn\compose\_column_transformer.py:481, in ColumnTransformer.get_feature_names_out(self, input_features)
    479 transformer_with_feature_names_out = []
    480 for name, trans, column, _ in self._iter(fitted=True):
--> 481     feature_names_out = self._get_feature_name_out_for_transformer(
    482         name, trans, column, input_features
    483     )
    484     if feature_names_out is None:
    485         continue

File ~\miniconda3\envs\Master_ML\lib\site-packages\sklearn\compose\_column_transformer.py:446, in ColumnTransformer._get_feature_name_out_for_transformer(self, name, trans, column, feature_names_in)
    444 # An actual transformer
    445 if not hasattr(trans, "get_feature_names_out"):
--> 446     raise AttributeError(
    447         f"Transformer {name} (type {type(trans).__name__}) does "
    448         "not provide get_feature_names_out."
    449     )
    450 if isinstance(column, Iterable) and not all(
    451     isinstance(col, str) for col in column
    452 ):
    453     column = _safe_indexing(feature_names_in, column)

AttributeError: Transformer log (type FunctionTransformer) does not provide get_feature_names_out.

Versions

scikit 1.0.2
@nilslacroix nilslacroix added Bug Needs Triage Issue requires triage labels Apr 27, 2022
@nilslacroix nilslacroix reopened this Apr 27, 2022
@glemaitre
Copy link
Member

get_feature_names_out will be available in 1.1.
We are releasing the RC today indeed. You might want to give a try then.

@nilslacroix
Copy link
Author

Thanks for the advice, I was a bit unsure, but there already seemed to be some get_feature_names_out functions in the transformers I used, so I thought this was implemented when the merge in november happened (referring to #21308 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue requires triage
Projects
None yet
Development

No branches or pull requests

2 participants
0