Machine Learning Basics·Machine learning from data to a responsible model

Data and features

Turn a table into features and keep the target separate.

Intermediate 14 min read Lesson 2 of 300 Challenge included
What you will be able to do
  • Separate X and y before any transformation.
  • Encode categorical variables deliberately.
  • Scale numeric features when the model is distance-based.
  • Check for leakage from the future or the target.

In plain English

Features are the inputs a model may use; the target is what you predict. Leakage happens when a feature contains information that would not be available at prediction time. Remove it before training.

features.pyPython
import pandas as pd

df = pd.DataFrame({
    'minutes': [12, 18, 9],
    'is_free': [True, False, True],
    'completed': [1, 1, 0],
})

X = df[['minutes', 'is_free']]
y = df['completed']
print(X.dtypes.tolist(), y.tolist())
Your turn

Remove a leaking column

Easy

Drop a column named final_score before training a model that predicts completion.

PYTHON · starter
X = df
Check your understanding before moving on.
Knowledge checkQuestion 1

What is data leakage?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 2 of 300 · 0% of course