Feature Scaling.

r.aruna devi
Analytics Vidhya
Published in
2 min readMay 26, 2020
Image from Google.

What is Feature Scaling ?

Feature Scaling is done on the dataset to bring all the different types of data to a Single Format. Done on Independent Variable.

Why we go for Feature Scaling ?

Example: Consider a dataframe has two columns of Experience and Salary.

Experience is represented in form of Years.

Salary is represented in form of Rupee.

  • When we map the two columns, the distance between the records are high.
  • Highly varies in Magnitude and Units.
  • Magnitude : Values in the column. Example : Years has 2,3,5 and Experience has 1100000,1250000 these are magnitude.
  • Units : Years and Rupee are units.

Some Algorithm, uses Euclideam Distance to calculate the target. If the data varies in Magnitude and Units, Distance between the Independent Variables will be more. SO,bring the data in such a way that Independent variables looks same and does not vary much in terms of magnitude.

from sklearn.preprocessing import StandardScaler
df_scaled = StandardScaler().fit_transform(df.values)
df_scaled = pd.DataFrame(df_scaled)
df_scaled
Output of Standard Scalar.

Types of Feature Scaling :

  • Min Max Scaler.
  • Standard Scaler.
  • Max Abs Scaler.
  • Robust Scaler.
  • Quantile Transformer Scaler.
  • Power Transformer Scaler.
  • Unit Vector Scaler.

Commonly used Scaling techniques are MinMaxScalar and Standard Scalar.

Min Max Scalar :

  • It scales and transforms the data inbetween 0 and 1.
  • ANN performs well when do scale the data using MinMaxScalar.
from sklearn.preprocessing import MinMaxScalerdf_minmax = MinMaxScaler().fit_transform(df.values)
df_minmax = pd.DataFrame(df_minmax)
df_minmax
Output of MinMaxScalar

Standard Scalar :

  • It scales and transform the data with respect to Mean = 0 and Standard Deviation = 1.
from sklearn.preprocessing import StandardScaler
df_scaled = StandardScaler().fit_transform(df.values)
df_scaled = pd.DataFrame(df_scaled)
df_scaled

Algorithm Uses Feature Scaling while Pre-processing :

  1. Linear Regression.
  2. Gradient Descent.
  3. K-Means
  4. K Nearest Neighbor.
  5. PCA
  • If we Scale the value, it will be easy to obtain the Global Minima Point.

Algorithms Don’t require Feature Scaling while pre-processing.

  1. Decision Tree.
  2. Random Forest.
  • All Tree Based Algorithm. The root node splits the value based on the data points.

--

--