Feature Engineering Techniques
Here are some of the most widely used Feature Engineering techniques, along with simple Python examples for each.
Encoding Categorical Variables
import pandas as pd
df = pd.DataFrame({"City": ["Noida", "Delhi", "Noida"]})
# One-hot encoding
df_encoded = pd.get_dummies(df, columns=["City"])
Scaling Numeric Features
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
df["ScaledIncome"] = scaler.fit_transform(df[["Income"]])
Binning Continuous Values
df["AgeGroup"] = pd.cut(df["Age"], bins=[0, 18, 35, 60, 100],
labels=["Teen", "Young Adult", "Adult", "Senior"])
Extracting Date Parts
df["OrderDate"] = pd.to_datetime(df["OrderDate"])
df["Month"] = df["OrderDate"].dt.month
df["Weekday"] = df["OrderDate"].dt.day_name()
Creating Ratio and Interaction Features
df["ExpensePerPerson"] = df["TotalExpense"] / df["FamilySize"]
df["PriceTimesQuantity"] = df["Price"] * df["Quantity"]
There's no universal "best" technique - the right choice depends on the model you're using and the nature of the data, so it's common to try several techniques and compare their impact on model performance.
Coming Up Next
Next, you'll shift focus to the basics of Probability - a foundation that underpins much of statistics and machine learning.