Skip to content

feature scaling

feature scaling, feature engineering, ai, ml

WHY FEATURE SCALING ?

The nature of certain data points maybe too huge compared to other features in the dataset / dataframe, this can cause the model to be biased. To avoid this issue, we can use feature scaling to normalize the values.

We'll look at methods of feature scaling.

  1. StandardScaler ( Also known as z-scaling )
  2. MinMaxScaler
  3. RobustScaler
from sklearn.preprocessing import StandardScaler, MinMaxScaler, RobustScaler
import numpy as np
import pandas as pd


s = StandardScaler()

# standard scraper / z-scaling

data = {"video_views": [800000, 1000000, 100000000]}


df = pd.DataFrame(data)
df["zscore"] = s.fit_transform(df[["video_views"]])

# min max scaler

m = MinMaxScaler()
df["minmax"] = m.fit_transform(df[["video_views"]])


# robust scaler

r = RobustScaler()
df["robust"] = r.fit_transform(df[["video_views"]])

print(df)