Addressing Data Leakage in Time Series
Lesson Overview
Welcome to today's lesson on addressing data leakage in time series data while preparing it for machine learning. In this lesson, you'll learn the importance of maintaining temporal order in your dataset splits to avoid forward-looking bias, which can misleadingly inflate your model's performance. We'll be using the Tesla ($TSLA) stock data as an example. By the end of this lesson, you'll understand how to partition your dataset correctly using TimeSeriesSplit from the sklearn.model_selection library.
Introduction to Data Leakage in Time Series
Data leakage occurs when information from outside the training dataset inadvertently makes its way into the model. This is particularly problematic in time series data, where the natural temporal ordering is crucial. Data leakage can lead to overestimation of a model's performance because it allows information from the future to be used in making predictions about the past.
When dealing with stock market data, using future prices to predict past prices would artificially inflate a model's accuracy and yield unreliable predictions for actual trading strategies. Hence, it's important to ensure that our training and testing sets are separated in a way that respects the temporal nature of the data.
Revisiting Feature Engineering and Scaling (Revision)
Let's quickly revise how to engineer features and scale them. These steps are foundational for preparing your data for machine learning models.
In this snippet, we create two new features, High-Low and Price-Open, and scale these features using StandardScaler.
Correctly Splitting Time Series Data
