MinMaxScaler#

En el escalado lineal se lleva cada columna al rango 0-1 con:

x_{*} = \frac{x-\min(x)}{\max(x) - \min(x)}

  • Es una alternativa al StandarScaler.

  • Permite robustes ante desviaciones estándar muy pequeñas.

[1]:
import seaborn as sns

penguins = sns.load_dataset("penguins")

data = penguins[["flipper_length_mm"]]
data = data.rename(columns={"flipper_length_mm": "original"})
[2]:
from sklearn.preprocessing import MinMaxScaler

minMaxScaler = MinMaxScaler(
    # -------------------------------------------------------------------------
    # Desired range of transformed data.
    feature_range=(0, 1),
    # -------------------------------------------------------------------------
    # Set to True to clip transformed values of held-out data to provided
    # feature range.
    # clip=False,
)
minMaxScaler.fit(data)

data["transformed"] = minMaxScaler.transform(data)
[3]:
g = sns.jointplot(x="original", y="transformed", data=data, kind="scatter")
g.fig.set_figwidth(3)
g.fig.set_figheight(3)
../_images/19_preprocesamiento_de_datos_02_MinMaxScaler_5_0.png
[4]:
display(
    minMaxScaler.min_,
    minMaxScaler.scale_,
    minMaxScaler.data_min_,
    minMaxScaler.data_max_,
    minMaxScaler.data_range_,
)
array([-2.91525424])
array([0.01694915])
array([172.])
array([231.])
array([59.])