21  Normalization and Standardization in R

Normalization and standardization are essential techniques in data preprocessing to scale numeric variables, ensuring that they contribute equally to statistical analysis and machine learning models. A dataset combining, say, rainfall in millimetres with fertilizer use in kilograms and yield in tons has variables on very different scales — applying these transformations prevents the largest-magnitude variable from silently dominating a model, and improves the efficiency of many algorithms.

21.1 Normalization

Normalization (also called min-max scaling) rescales numeric variables into a fixed range, usually [0, 1] or [-1, 1]. This ensures that all features share the same scale, so variables with large ranges don’t dominate ones with smaller ranges.

Formula for min-max normalization

\[ X' = \frac{X - X_{min}}{X_{max} - X_{min}} \]

where:

  • \(X'\) is the normalized value.
  • \(X\) is the original value.
  • \(X_{min}\) and \(X_{max}\) are the minimum and maximum values in the dataset.

When to use normalization?

  • When data follows a non-Gaussian (skewed) distribution.
  • When features need to be scaled between 0 and 1 (e.g., for machine learning).
  • When working with neural networks and distance-based algorithms (e.g., k-NN, SVM).

21.1.1 Implementation of Normalization in R

Both columns now range from 0 to 1, giving rainfall and fertilizer use equal weight in any model built on this data.


21.2 Standardization

Standardization (also known as z-score scaling) transforms data by centering it around a mean of 0 and scaling it by its standard deviation. Unlike min-max normalization, it does not bound values to a fixed range.

Formula for z-score standardization

\[ X' = \frac{X - \mu}{\sigma} \]

where:

  • \(X'\) is the standardized value.
  • \(X\) is the original value.
  • \(\mu\) is the mean of the dataset.
  • \(\sigma\) is the standard deviation of the dataset.

When to use standardization?

  • When data follows a normal (Gaussian) distribution.
  • When using linear regression, logistic regression, PCA, or clustering.
  • When handling outliers, since it is less sensitive to extreme values than normalization.

21.2.1 Implementation of Standardization in R

The transformed data now has a mean of 0 and a standard deviation of 1 in each column, which makes it suitable for statistical modeling.


21.3 Key Differences Between Normalization and Standardization

Feature Normalization Standardization
Definition Rescales values to a fixed range (typically 0 to 1). Transforms values to have a mean of 0 and a standard deviation of 1.
Formula \(X' = \frac{X - X_{min}}{X_{max} - X_{min}}\) \(X' = \frac{X - \mu}{\sigma}\)
Effect on data Retains the original distribution’s shape but compresses values into a fixed range. Adjusts the data toward a standard normal (bell-shaped) distribution.
Range Typically [0, 1] (min-max scaling). Centered around 0, without fixed bounds.
Best used when Data does not follow a normal distribution. Data follows (or approximately follows) a normal distribution.
Sensitive to outliers? Yes — a single extreme value can distort the scaling. No — since it uses mean and standard deviation, it’s more robust to outliers.
Example dataset Rainfall in mm across farms (e.g., 540–1,450 mm). Yield per hectare that varies by crop and season.
Common applications Neural networks, k-NN, distance-based models (SVM, clustering). Linear regression, logistic regression, PCA.

21.3.1 When to Use Normalization vs. Standardization?

  • Use normalization when:
    • Your data has varying scales and does not follow a normal distribution.
    • You are using distance-based models like k-NN, k-means, or neural networks.
    • Features have different units (e.g., rainfall in mm, fertilizer in kg).
  • Use standardization when:
    • Your data follows a Gaussian (normal) distribution.
    • You are using models that assume normality, like linear regression, PCA, logistic regression.
    • You need a dataset where outliers have less impact.

21.4 Practical Applications of Normalization and Standardization

Domain Use Case Method Reason for Preference
Precision Agriculture Soil sensor readings (moisture, pH, NPK) Normalization Sensor readings span very different native ranges; scaling to [0, 1] keeps every input comparable before feeding a model.
Machine Learning Neural networks Normalization Keeps feature values within a (0, 1) range, improving model convergence.
Machine Learning PCA Standardization PCA assumes normally distributed data; z-score scaling ensures proper feature weights.
Machine Learning k-NN algorithm Normalization k-NN is distance-based; scaling prevents one feature from dominating others.
Agribusiness Forecasting Crop yield prediction Standardization Combining yield, rainfall, and fertilizer data (very different scales and roughly normal distributions) benefits from z-score scaling.
Finance Commodity price prediction Standardization Prices vary widely across crops; standardization makes comparisons meaningful.
Supply Chain Demand forecasting Standardization Ensures seasonal fluctuations are balanced for forecasting accuracy.
Image Processing Satellite/drone crop imagery Normalization Pixel intensities are scaled (0 to 1) for better visualization and deep-learning models.

Summary

Concept Description
Normalization and Standardization in R
Normalization Rescales numeric variables into a fixed range, usually [0,1], using min-max scaling
Standardization Transforms data to a mean of 0 and standard deviation of 1, using z-score scaling
Normalization vs. Standardization Normalization suits skewed, distance-based use cases; standardization suits roughly normal data and models like PCA and regression
Practical Applications Precision agriculture, yield prediction, and image processing typically favor normalization or standardization depending on the model and data distribution