Let’s say we have a dataset. The dataset has several columns. And we want to transform different columns differently. For example, we may want to use Standard Scaler for one column, and Min-Max Scaler for another column.
One way to do it is to use the Standard Scaler and Min-Max Scaler separately, and call them one by one. But that may become inconvenient. So, we can use ColumnTransformer instead.
Let’s read the penguins dataset. Some columns of the dataset contain numerical data that have a normal distribution. And the values of some numerical columns are not normally distributed. Now, we want to scale the features.
Now, we can use StandardScalar for columns for which the data is normally distributed. And if the data in some columns are not normally distributed, we can use the Min-Max Scaler.
Now, let’s read the penguins dataset using the seaborn library. Let’s also plot KDE plots for the data of each numerical column.
import seaborn from matplotlib import pyplot df = seaborn.load_dataset("penguins") print(df.info()) fig, axes = pyplot.subplots(2, 2) seaborn.kdeplot(data=df, x="bill_length_mm", ax=axes[0,0]) seaborn.kdeplot(data=df, x="bill_depth_mm", ax=axes[0,1]) seaborn.kdeplot(data=df, x="flipper_length_mm", ax=axes[1,0]) seaborn.kdeplot(data=df, x="body_mass_g", ax=axes[1,1]) pyplot.show()
The resulting plot shows the following:






0 Comments