Forecasting
Another use of regression is for forecasting. For example, we can forecast future values in a time series like security prices, the weather, sales, or web traffic data. Let's use our daily bitcoin price data from Chapter 4, Loading and Wrangling Data with Pandas and NumPy as an example:
btc_df = pd.read_csv('data/bitcoin_price.csv')
btc_df['time'] = pd.to_datetime(btc_df['time'], unit='ms')
btc_df.set_index('time', inplace=True)
btc_df = btc_df[['close', 'volume']]
We load the data and only keep the closing price and volume. We are also setting the time column as the index after parsing it to a datetime. The units for the time column are milliseconds since the epoch.
To create a target column with future closing price data, we can use a pandas function:
btc_df['close_1d_future'] = btc_df['close'].shift(-1)
btc_df.dropna(inplace=True)
The shift
function...