Skip to content

Add strategy="constant" to SimpleImputerΒ #11208

Closed
@ogrisel

Description

@ogrisel

SimpleImputer should accept array-like with object, string and categorical dtypes (e.g. pandas dataframes storing categorical variables) and make it possible to replace the np.nan marker by another constant value passed by the user in the constructor.

In particular this would make the ColumnTransformer example #11197 much simpler as suggested by @TomDLT:

num_pl = make_pipeline(
    SimpleImputer(strategy='median'),
    StandardScaler(),
)
cat_pl = make_pipeline(
    SimpleImputer(strategy='constant', fill_value="missing"),
    CategoricalEncoder('onehot-dense'),
)
transformer = ColumnTransformer(
    [
        ('num', num_pl, num_feats),
        ('cat', cat_pl, cat_feats)
    ],
    remainder='drop'
)

Note that this will require to also fix #2888 at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions