Learn/Data Science/Chapter 20

Chapter 20 of 30

Keep learning and build your Data Science skills.

67%
Chapter 20

Feature Engineering

Learn how useful features can be created from existing data.

Theory

Feature Engineering is the process of creating, transforming, or selecting variables that help analytical or machine learning models. Examples include: • Extracting year from a date • Creating age groups • Calculating ratios • Combining existing columns • Encoding categories Good features can make patterns easier for a model to learn.

Example

import pandas as pd

df = pd.DataFrame({
    "Height": [1.60, 1.70, 1.80],
    "Weight": [55, 65, 80]
})

df["BMI"] = (
    df["Weight"] /
    (df["Height"] ** 2)
)

print(df)

Output

A BMI feature is created from height and weight.

Practice

Create at least three useful features from an existing dataset.

Interview Questions

1

What is feature engineering?

2

Why is feature engineering useful?

3

Give an example of feature engineering.

Quick Quiz

Which option best describes this chapter?

A.Creating useful variables
B.Deleting all data
C.Building web servers
D.Creating CSS layouts