<p dir="auto">When I use ColumnTransformer to preprocess different columns (include numeric, category, text) with pipeline, I cannot get the feature names of the final transformed data, which is hard for debugging.</p>
<p dir="auto">Here is the code:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="titanic_url = ('https://raw.githubusercontent.com/amueller/'
               'scipy-2017-sklearn/091d371/notebooks/datasets/titanic3.csv')

data = pd.read_csv(titanic_url)

target = data.pop('survived')

numeric_columns = ['age','sibsp','parch']
category_columns = ['pclass','sex','embarked']
text_columns = ['name','home.dest']

numeric_transformer = Pipeline(steps=[
    ('impute',SimpleImputer(strategy='median')),
    ('scaler',StandardScaler()
    )
])
category_transformer = Pipeline(steps=[
    ('impute',SimpleImputer(strategy='constant',fill_value='missing')),
    ('ohe',OneHotEncoder(handle_unknown='ignore'))
])
text_transformer = Pipeline(steps=[
    ('cntvec',CountVectorizer())
])

preprocesser = ColumnTransformer(transformers=[
    ('numeric',numeric_transformer,numeric_columns),
    ('category',category_transformer,category_columns),
    ('text',text_transformer,text_columns[0])
])

preprocesser.fit_transform(data)"><pre class="notranslate"><span class="pl-s1">titanic_url</span> <span class="pl-c1">=</span> (<span class="pl-s">'https://raw.githubusercontent.com/amueller/'</span>
               <span class="pl-s">'scipy-2017-sklearn/091d371/notebooks/datasets/titanic3.csv'</span>)

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_csv</span>(<span class="pl-s1">titanic_url</span>)

<span class="pl-s1">target</span> <span class="pl-c1">=</span> <span class="pl-s1">data</span>.<span class="pl-en">pop</span>(<span class="pl-s">'survived'</span>)

<span class="pl-s1">numeric_columns</span> <span class="pl-c1">=</span> [<span class="pl-s">'age'</span>,<span class="pl-s">'sibsp'</span>,<span class="pl-s">'parch'</span>]
<span class="pl-s1">category_columns</span> <span class="pl-c1">=</span> [<span class="pl-s">'pclass'</span>,<span class="pl-s">'sex'</span>,<span class="pl-s">'embarked'</span>]
<span class="pl-s1">text_columns</span> <span class="pl-c1">=</span> [<span class="pl-s">'name'</span>,<span class="pl-s">'home.dest'</span>]

<span class="pl-s1">numeric_transformer</span> <span class="pl-c1">=</span> <span class="pl-v">Pipeline</span>(<span class="pl-s1">steps</span><span class="pl-c1">=</span>[
    (<span class="pl-s">'impute'</span>,<span class="pl-v">SimpleImputer</span>(<span class="pl-s1">strategy</span><span class="pl-c1">=</span><span class="pl-s">'median'</span>)),
    (<span class="pl-s">'scaler'</span>,<span class="pl-v">StandardScaler</span>()
    )
])
<span class="pl-s1">category_transformer</span> <span class="pl-c1">=</span> <span class="pl-v">Pipeline</span>(<span class="pl-s1">steps</span><span class="pl-c1">=</span>[
    (<span class="pl-s">'impute'</span>,<span class="pl-v">SimpleImputer</span>(<span class="pl-s1">strategy</span><span class="pl-c1">=</span><span class="pl-s">'constant'</span>,<span class="pl-s1">fill_value</span><span class="pl-c1">=</span><span class="pl-s">'missing'</span>)),
    (<span class="pl-s">'ohe'</span>,<span class="pl-v">OneHotEncoder</span>(<span class="pl-s1">handle_unknown</span><span class="pl-c1">=</span><span class="pl-s">'ignore'</span>))
])
<span class="pl-s1">text_transformer</span> <span class="pl-c1">=</span> <span class="pl-v">Pipeline</span>(<span class="pl-s1">steps</span><span class="pl-c1">=</span>[
    (<span class="pl-s">'cntvec'</span>,<span class="pl-v">CountVectorizer</span>())
])

<span class="pl-s1">preprocesser</span> <span class="pl-c1">=</span> <span class="pl-v">ColumnTransformer</span>(<span class="pl-s1">transformers</span><span class="pl-c1">=</span>[
    (<span class="pl-s">'numeric'</span>,<span class="pl-s1">numeric_transformer</span>,<span class="pl-s1">numeric_columns</span>),
    (<span class="pl-s">'category'</span>,<span class="pl-s1">category_transformer</span>,<span class="pl-s1">category_columns</span>),
    (<span class="pl-s">'text'</span>,<span class="pl-s1">text_transformer</span>,<span class="pl-s1">text_columns</span>[<span class="pl-c1">0</span>])
])

<span class="pl-s1">preprocesser</span>.<span class="pl-en">fit_transform</span>(<span class="pl-s1">data</span>)</pre></div>
<ol dir="auto">
<li><code class="notranslate">preprocesser.get_feature_names()</code> will get error:<br>
<code class="notranslate">AttributeError: Transformer numeric (type Pipeline) does not provide get_feature_names.</code></li>
<li>In <code class="notranslate">ColumnTransformer</code>，<code class="notranslate">text_transformer</code> can only process a string (eg 'Sex'), but not a list of string as <code class="notranslate">text_columns</code></li>
</ol>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="134096165" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6372" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/6372/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/6372">#6372</a> adds <code class="notranslate">get_feature_names</code> to <code class="notranslate">PolynomialFeatures</code>. It accepts a list of names of <code class="notranslate">input_features</code> (or substitutes with defaults) and constructs feature name strings that are human-readable and informative. Similar support should be available for other transformers, including feature selectors, feature agglomeration, <code class="notranslate">FunctionTransformer</code>, and perhaps even PCA (giving the top contributors to each component). <code class="notranslate">FeatureUnion</code> should be modified to handle the case where an argument is supplied. A proposal for support in <code class="notranslate">Pipeline</code> is given in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="135590071" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6424" data-hovercard-type="issue" data-hovercard-url="/scikit-learn/scikit-learn/issues/6424/hovercard" href="https://github.com/scikit-learn/scikit-learn/issues/6424">#6424</a>.</p>
<p dir="auto">Modelled on <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="134096165" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6372" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/6372/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/6372">#6372</a>, each enhancement can be contributed as a separate PR. Note that default names for features are <code class="notranslate">[x0, x1, ...]</code></p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">PolynomialFeatures</code> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/amueller/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/amueller">@amueller</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="134096165" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6372" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/6372/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/6372">#6372</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> feature selection and randomized L1 <a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/yenchenlin1994/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/yenchenlin1994">@yenchenlin1994</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> feature agglomeration <a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/yenchenlin1994/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/yenchenlin1994">@yenchenlin1994</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">FunctionTransformer</code> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/nelson-liu/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/nelson-liu">@nelson-liu</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="135753025" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6431" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/6431/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/6431">#6431</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> scalers, normalizers and imputers: should be trivial like <code class="notranslate">FunctionTransformer</code> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="135753025" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6431" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/6431/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/6431">#6431</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">Binarizer</code> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="135753025" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6431" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/6431/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/6431">#6431</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">OneHotEncoder</code> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="135957352" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6441" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/6441/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/6441">#6441</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <code class="notranslate">FeatureUnion</code> <a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/yenchenlin1994/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/yenchenlin1994">@yenchenlin1994</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> PCA?</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <code class="notranslate">SparseRandomProjection</code>?</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <code class="notranslate">GaussianRandomProjection</code>??</li>
<li>other transformers?</li>
</ul>