Transformers and time series modeling
Before jumping into transformers for time series modeling, it is helpful to understand basic approaches such as the moving average. This approach takes a window of historical data and applies an average to find the future value. Then, it continues to iterate over the data and find the next value using the next steps:
- In order to illustrate this approach, we first need to get the data using
yfinance
, and then install the package:pip install yfinance
- Then, you can easily fetch the data:
import yfinance as yf btc_ticker = yf.Ticker("BTC-USD") btc_data = btc_ticker.history(period="max")
The data will be fetched, and you can easily see it by printing out the variable:
btc_data
It will show you a nice pandas DataFrame, as shown in Figure 18.2.
Figure 18.2 – Historical Bitcoin data
- You can also easily visualize it with the following code:
from matplotlib import pyplot as plt plt.plot...