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
B. Fill with mean
C. Fill with median
D. Fill categorical values with mode
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:- Label Encoding
- 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:Code
Output
Remember
Categorical data → Convert text into numbers.
3. Feature Scaling
Definition
Feature Scaling puts numerical features into a similar range. Example: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: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