Data and features
Turn a table into features and keep the target separate.
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.
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
EasyRemove a leaking column
Drop a column named final_score before training a model that predicts completion.
PYTHON · starter
X = dfCheck 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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.