[Python] How to select and transform cols with sklearn pipeline and preserver original names?

Discussão em 'Python' iniciado por Stack, Março 13, 2025.

  1. Stack

    Stack Membro Participativo

    Here, the purpose is to select a few cols from a dataframe. Then apply log transformation some of the selected cols.

    log_transformer = FunctionTransformer(lambda x: np.log2(x + 1), validate=False, feature_names_out="one-to-one")

    preprocessor = ColumnTransformer([
    ("selector", "passthrough", selected_cols),
    ("log_transform", log_transformer, log_cols),
    ], remainder="drop", verbose_feature_names_out=False)

    pipeline = Pipeline([
    ("preprocessor", preprocessor)
    ]).fit(train_df)


    Here, the software ask me to set verbose_feature_names_out=True. Is there a way to prevent "selector" and "log_transform" prefixes to be added to the col names?

    Continue reading...

Compartilhe esta Página