8000 AttributeError: Transformer ordinalencoder (type OrdinalEncoder) does not provide get_feature_names_out. · Issue #21304 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

AttributeError: Transformer ordinalencoder (type OrdinalEncoder) does not provide get_feature_names_out. #21304

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
jonathan-hourany opened this issue Oct 11, 2021 · 2 comments

Comments

@jonathan-hourany
Copy link
jonathan-hourany commented Oct 11, 2021

Describe the bug

When using ColumnTransformer, OrdinalEncoder does not support get_feature_names_out even though ColumnTransformer should be able to provide one.

Steps/Code to Reproduce

import pandas as pd
from sklearn.pipeline import make_pipeline, make_union
from sklearn.compose import make_column_transformer
from sklearn.preprocessing import OrdinalEncoder

df = pd.DataFrame(
        data={
            "bar": ["1", "2", "3"],
        }
    )

ord_pipe = make_column_transformer((OrdinalEncoder(), ["bar"]))
ord_pipe.fit(df)
ord_pipe.get_feature_names_out()

Expected Results

No error is thrown

Actual Results

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-49a0474fed14> in <module>
----> 1 ord_pipe.get_feature_names_out()

~/.pyenv/versions/3.9.7/envs/ltr/lib/python3.9/site-packages/sklearn/compose/_column_transformer.py in 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             )

~/.pyenv/versions/3.9.7/envs/ltr/lib/python3.9/site-packages/sklearn/compose/_column_transformer.py in _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."

AttributeError: Transformer ordinalencoder (type OrdinalEncoder) does not provide get_feature_names_out.

Versions

System:
python: 3.9.7 (default, Sep 7 2021, 14:05:40) [GCC 9.3.0]
executable: /home/proto/.pyenv/versions/3.9.7/envs/ltr/bin/python3.9
machine: Linux-5.4.0-88-generic-x86_64-with-glibc2.31

Python dependencies:
pip: 21.2.4
setuptools: 57.4.0
sklearn: 1.0
numpy: 1.21.2
scipy: 1.7.1
Cython: None
pandas: 1.3.3
matplotlib: 3.4.3
joblib: 1.0.1
threadpoolctl: 2.2.0

Built with OpenMP: True

@glemaitre
Copy link
Member

get_features_names_out of ColumnTransformer will work if the get_features_names_out is implemented for all transformers and predictors in the pipeline or column transformer.

We aim at adding this method to all transformers for 1.1

@adrinjalali
Copy link
Member

This issue would track them #21308

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

No branches or pull requests

3 participants
0