← Back to list

Data Preprocessing in Machine Learning: Encoding and Feature Scaling Explained

Machine Learning models do not understand raw real-world data directly. Before building any model, the dataset must be cleaned and…

Anu · 2026-06-09 15:06 · 0 claps · 4.4 min read
#nlp #python #mls #distancebased
Open on Medium ↗
Wiki topics: ML · Machine Learning EDU · Education & Learning 💻 · Programming

Data Preprocessing in Machine Learning: Encoding and Feature Scaling Explained

Machine Learning models do not understand raw real-world data directly. Before building any model, the dataset must be cleaned and transformed into a suitable format. This process is called Data Preprocessing, and it plays a critical role in improving model performance and accuracy.

Press enter or click to view image in full size

What is Data Preprocessing?

Data preprocessing is the process of converting raw data into a clean and understandable format before training a Machine Learning model.

Real-world datasets often contain:

  • Categorical values
  • Different feature ranges
  • Missing values
  • Duplicate records
  • Inconsistent data

If preprocessing is not performed properly, the model may produce inaccurate predictions and poor performance

Encoding Techniques in Machine Learning

Encoding is a preprocessing technique used to convert categorical (text) data into numerical format because Machine Learning algorithms work only with numbers.

In this article, I explored three commonly used encoding techniques:

✅ Label Encoding ✅ One-Hot Encoding ✅ Ordinal Encoding

1. Label Encoding

Label Encoding converts each category into a unique numerical value.

Example

Press enter or click to view image in full size

Label Encoding

Example Label Encoding

2. One-Hot Encoding

One-Hot Encoding creates separate columns for each category and represents them using 0 and 1.

Press enter or click to view image in full size

One Hot Encoding

Press enter or click to view image in full size

example One Hot Encoding

3. Ordinal Encoding

Ordinal Encoding is used when categories have a meaningful order or ranking.

Press enter or click to view image in full size

Ordinal Encoding

Example OrdinalEncoder

Conclusion

Encoding is an important preprocessing step in Machine Learning.

  • Label Encoding is useful for binary categories.
  • One-Hot Encoding is best for unordered categorical data.
  • Ordinal Encoding is suitable for ordered categories.

Choosing the correct encoding technique helps improve model performance and prevents incorrect assumptions during training.

Feature Scaling in Machine Learning

Feature Scaling is a preprocessing technique used to bring all feature values into a similar range. In many datasets, features may contain different scales or units.

Example

  • Age → 25
  • Salary → 50000

Here, the Salary feature has much larger values than Age. Some Machine Learning algorithms may give more importance to large-value features, which can affect model performance.

Feature Scaling solves this problem by transforming features into a common scale

Why Feature Scaling is Important

✅ Improves model accuracy ✅ Helps algorithms learn faster ✅ Prevents large-value features from dominating ✅ Improves distance-based calculations

Feature Scaling is especially important for algorithms like:

  • KNN
  • K-Means
  • Logistic Regression
  • Linear Regression
  • SVM

Types of Feature Scaling

1. Standardization

Standard Scaler is a feature scaling technique used to standardize data by transforming features into a common scale. It converts the data so that the mean becomes 0 and the standard deviation becomes 1.

It is one of the most commonly used preprocessing techniques in Machine Learning.

Press enter or click to view image in full size

Press enter or click to view image in full size

Example StandardScaler

Min-Max Scaler in Machine Learning

Min-Max Scaler is a feature scaling technique used to transform data into a fixed range, usually between 0 and 1. It is also called Normalization.

This method scales all feature values proportionally so that the smallest value becomes 0 and the largest value becomes 1.

Press enter or click to view image in full size

Press enter or click to view image in full size

Why Min-Max Scaling is Important

✅ Brings all features into the same range ✅ Improves model performance ✅ Useful for distance-based algorithms ✅ Prevents large-value features from dominating

Algorithms That Commonly Use Min-Max Scaler

  • K-Nearest Neighbors (KNN)
  • Neural Networks
  • K-Means Clustering
  • Deep Learning Models

Robust Scaler in Machine Learning

Robust Scaler is a feature scaling technique used to scale data while handling outliers effectively. Unlike Standard Scaler and Min-Max Scaler, Robust Scaler uses the Median and Interquartile Range (IQR) instead of mean and standard deviation.

It is useful when the dataset contains extreme values or outliers.

Press enter or click to view image in full size

Why Robust Scaler is Important

✅ Handles outliers effectively ✅ Reduces the impact of extreme values ✅ Improves model stability ✅ Works well for skewed data

When to Use Robust Scaler

Use Robust Scaler when:

  • Dataset contains many outliers
  • Data distribution is skewed
  • Extreme values affect model performance

Real-World Applications

Data preprocessing is used in:

  • Recommendation Systems
  • Fraud Detection
  • Medical Diagnosis
  • NLP
  • Image Recognition

Without preprocessing, even advanced models perform poorly.

Without preprocessing, even advanced models perform poorly.

Conclusion

Data preprocessing is one of the most important steps in Machine Learning.

Good preprocessing improves:

  • model accuracy
  • training speed
  • prediction quality
  • stability

메타데이터
post_id
0d3c2327b684
slug
data-preprocessing-in-machine-learning-encoding-and-feature-scaling-explained-0d3c2327b684
url
https://medium.com/@anu12670/data-preprocessing-in-machine-learning-encoding-and-feature-scaling-explained-0d3c2327b684
canonical_url
https://medium.com/@anu12670/data-preprocessing-in-machine-learning-encoding-and-feature-scaling-explained-0d3c2327b684
author_url
https://medium.com/@anu12670
status
ok
fetched_at
2026-06-11 22:20:54