Interpolation: Inbetween Times
In this exercise, you will build a linear model by fitting monthly time-series data for the Dow Jones Industrial Average (DJIA) and then use that model to make predictions for daily data (in effect, an interpolation). Then you will compare that daily prediction to the real daily DJIA data.
A few notes on the data. "OHLC" stands for "Open-High-Low-Close", which is usually daily data, for example the opening and closing prices, and the highest and lowest prices, for a stock in a given day. "DayCount" is an integer number of days from start of the data collection.
Diese Übung ist Teil des Kurses
Introduction to Linear Modeling in Python
Anleitung zur Übung
- Use
ols()
to.fit()
a model to thedata=df_monthly
withformula="Close ~ DayCount"
. - Use
model_fit.predict()
on bothdf_monthly.DayCount
anddf_daily.DayCount
to predict values for the monthly and dailyClose
prices, stored as a new columnModel
in each DataFrame. - Use the predefined
plot_model_with_data
twice, on eachdf_monthly
anddf_daily
and compare the RSS values shown.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# build and fit a model to the df_monthly data
model_fit = ols('Close ~ DayCount', ____=df_monthly).____()
# Use the model FIT to the MONTHLY data to make a predictions for both monthly and daily data
df_monthly['Model'] = model_fit.____(df_monthly.____)
df_daily['Model'] = model_fit.____(df_daily.____)
# Plot the monthly and daily data and model, compare the RSS values seen on the figures
fig_monthly = plot_model_with_data(____)
fig_daily = plot_model_with_data(____)