Skip to content Skip to sidebar Skip to footer

How To Use The `columntransformer`?

I'm trying to use the ColumnTransformer of scikitlearn. Here's what I have : median_imputer = SimpleImputer(strategy = 'median') mean_imputer = SimpleImputer(strategy = 'mean') ct

Solution 1:

You are passing the actual column data for the third element of each triple (X_train.LotFrontage etc.). You should instead pass the name of the column(s) [there are other options, see the docs], e.g.

ct = ColumnTransformer([
    ("med_imp", median_imputer, ["LotFrontage", "MasVnrArea"]),
    ("mean_imp", mean_imputer, ["GarageYrBlt"])
])

(Since imputers operate on 2D inputs, you need to provide a list of columns. And I've grouped two together and used your mean_imputer just to make the example a little more complex.)

Post a Comment for "How To Use The `columntransformer`?"