Scaling

Normalise data with various scaling methods

Objective

Feature scaling normalises data to improve model accuracy and comparability across features.

Key methods include:

  1. Max scaler Scales features between -1 and 1 using absolute max, sensitive to outliers.

  2. Min-Max scaler Scales features to a specified range, e.g., [0,1], but sensitive to outliers.

  3. Robust scaler Uses median and interquartile range, resistant to outliers.

  4. Standard scaler Centers data around 0 with standard deviation of 1, ideal for normally distributed data.

These methods offer flexibility by allowing custom variables for optimal data scaling.

Max scaler

The Max Scaler sets the data between -1 and 1. It scales data according to the absolute maximum, this scaler is not suitable for outliers.

It needs data pre-processing, such as handling outliers.

Attributes

Attribute
Description
Type
Required

absolute max

The column absolute max of the feature

Double

Example

feature engineering:
  ...
  features:
    compute:
      scaled_price:
        function:
          max scaler:
            source field: price
            variables:
              absolute max: 12.78

Min-Max Scaler

Transform features by scaling each feature to a given range.

This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. This scaler shrinks the data within the range of -1 to 1, if there are negative values.

We can set the range [0,1] or [0,5] or [-1,1]. This Scaler responds well if the standard deviation is small and the distribution is not Gaussian.

This scaler is sensitive to outliers.

Attributes schema

Attribute
Description
Type
Required

min

The column min of the feature

Double array

max

The column max of the feature

Double array

interval

Double array

Example

feature engineering:
  ...
  features:
    compute:
      scaled_price:
        function:
          minmax scaler:
            source field: price
            variables:
              min: 10.00
              max: 12.78

Robust scaler

The robust scaler is a median-based scaling method.

The formula of robust scaler is (Xi-Xmedian) Xiqr. This scalar is not affected by outliers.

Since it uses the interquartile range, it absorbs the effects of outliers while scaling. The interquartile range (Q3 — Q1) has half the data point. If we have outliers that might affect the results or statistics and do not want to remove them, robust scaler is the best choice.

Attributes schema

Attribute
Description
Type
Required

median

The column min of the feature

Double

q1

The column Q1 interquartile range of the feature

Double

q3

The column Q3 interquartile range of the feature

Double

iqr

The calculated interquartile range difference of q3 and q1

Double

Example

feature engineering:
  ...
  features:
    compute:
      scaled_price:
        function:
          robust scaler:
            source field: price
            variables:
              median: 8.78
              q3: 11.78 
              q1: 7.67

Standard scaler

The standard scaler assumes data is normally distributed within each feature and scales them such that the distribution centered around 0, with a standard deviation of 1.

Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set.

If data is not normally distributed, this is not the best scaler to use.

Attributes schema

Attribute
Description
Type
Required

population mean

The column population mean of the feature

Double

population std

The column population standard deviation of the feature

Double

Example

feature engineering:
  ...
  features:
    compute:
      scaled_price:
        function:
          standard scaler:
            source field: price
            variables:
              population mean: 11.15
              population std: 1.48

Last updated