
So, we can see that body mass is normally distributed, whereas bill length, bill depth, and flipper length are not. So, in this example, we will use StandardScaler for the body mass column and MinMaxScaler for the rest of the numerical columns.
We will use the Column Transformer here. We can use the following Python code for that purpose.
import seaborn
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import LabelEncoder, MinMaxScaler, StandardScaler
df = seaborn.load_dataset("penguins")
print(df.info())
column_transformer = ColumnTransformer([("min_max_scaler", MinMaxScaler(), ["bill_length_mm", "bill_depth_mm", "flipper_length_mm"]), ("standard_scaler", StandardScaler(), ["body_mass_g"])])
df[["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"]] = column_transformer.fit_transform(
df[["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"]])
print(df.head())
Here, we are using the following Python statement to initialize the column transformer…








































0 Comments