Skip to main content

What is Feature Engineering?

Feature Engineering is the process of creating, modifying, or selecting features so that machine learning models can learn better from the data. Example: Suppose we have: Before giving this data to a machine learning model, we may need to:

1. Missing Value Handling

Definition

A missing value means some data is not available. Example: NaN means the value is missing.

Common Methods

A. Remove rows

Removes rows containing missing values.

B. Fill with mean

Replaces missing values with the average.

C. Fill with median

Useful when data contains outliers.

D. Fill categorical values with mode

Uses the most frequently occurring value.

Example

Output

Remember

Missing values → Remove or fill them appropriately.

2. Encoding Categorical Variables

Definition

Machine learning models generally work with numbers, but real-world data often contains text. Example:
We convert categorical values into numerical values. Two common methods:
  1. Label Encoding
  2. One-Hot Encoding

A. Label Encoding

Converts categories into numbers.

Code

Output

Use

Generally useful for ordinal categories or binary categories.

B. One-Hot Encoding

Creates separate columns for each category. Original:
After encoding:

Code

Output

Remember

Categorical data → Convert text into numbers.

3. Feature Scaling

Definition

Feature Scaling puts numerical features into a similar range. Example:
Salary has much larger values than Age. Some algorithms can be affected by this difference.

Common Scaling Methods

  • Standardization
  • Min-Max Scaling

A. StandardScaler

Standardization transforms data so that it generally has:

Code

Output


B. MinMaxScaler

Converts values generally into the range:

Code

Output

When is scaling important?

Especially for algorithms based on distance or magnitude, such as:
  • K-Means
  • KNN
  • SVM
  • PCA
  • Neural Networks

Remember

Feature Scaling → Put numerical features on comparable scales.

4. Feature Selection

Definition

Feature Selection means selecting the most useful features and removing unnecessary ones. Example: Suppose we have:
Maybe only these are useful:
We remove irrelevant features.

Why?

Feature selection can:
  • Reduce model complexity
  • Reduce training time
  • Remove irrelevant information
  • Reduce overfitting
  • Sometimes improve model performance

Simple Example

Output

Customer_ID was removed because it usually doesn’t provide useful predictive information.

Common Feature Selection Methods


Complete Feature Engineering Flow

Quick Comparison

Easy way to remember

Missing values → Fix the data Encoding → Convert text to numbers Scaling → Normalize numerical ranges Selection → Keep important features