Exercise 2: Prepare Data for Training¶
Objective¶
In this lab, we will:
- Load the Processed Dataset
- Define Features and Target Variable
- Prepare the Data for Model Training
What you will learn
- How to select numerical and categorical features for a regression task.
- The importance of the train-test split to prevent data leakage.
- How to persist processed splits for downstream model training.
MLOps Perspective
Feature engineering and data splitting are often sources of "training-serving skew." By explicitly defining features and saving splits, we create a reproducible artifact that ensures the model is evaluated on data it has never seen. Data preparation is not just about cleaning; it's about creating a reproducible data pipeline. In a professional environment, these steps would be encapsulated in a pipeline component (like a Kubeflow component), ensuring that the exact same transformations are applied to training and production data.
Prerequisites¶
- Cleaned dataset saved in directory
data/processed
Step 1: Find and Open the Jupyter Notebook¶
In directory "labs/01_beginner/bike_demand_forecasting", please open the second notebook, "02_data_preparation.ipynb", and follow the instructions below to complete the tasks.
Step 2: Load the Processed Data¶
In this task, we take the cleaned dataset from the last task (data/processed) and prepare it for model training.
Add the cleaned data for the first three months in the appropriate cell:
Step 3: Set the Categorical Features¶
We already have set the numerical features.
You only need to set these categorical features:
Step 4: Split the DataSet into Training and Test DataSets¶
In order to split the dataset into training and testing datasets, data scientists usually use train_test_split function from sklearn.model_selection module.
Just add this line of code in the appropriate cell, without any changes:
Step 5: Inspect the Split Data¶
Check the shape of your training and test datasets to confirm the split was successful:
Just paste this line in a cell under the same notebook and run it.
(Optional) You can also print out the first 5 rows of both training and test data:
Summary¶
In this exercise, you:
- Loaded the cleaned dataset from the previous exercise
- Defined features and target variable for training
- Split the data into training and test datasets
- Verified the split data shapes