Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question re: 05_1_TimeSeries_HistoricalEvents! #10

Open
afogarty85 opened this issue Feb 13, 2022 · 0 comments
Open

Question re: 05_1_TimeSeries_HistoricalEvents! #10

afogarty85 opened this issue Feb 13, 2022 · 0 comments

Comments

@afogarty85
Copy link

afogarty85 commented Feb 13, 2022

Good Afternoon! Thank you very much for all you have done with these repositories of knowledge! I had a question about the file: 05_1_TimeSeries_HistoricalEvents.ipynb

In the case of the solution code here:

############### Solution ###############
offset = '7D'

data_window = df_train[['product_id', 'date', 'target']].groupby(['product_id', 'date']).agg(['count', 'sum']).reset_index()
data_window.columns = ['product_id', 'date', 'count', 'sum']
data_window.index = data_window['date']

data_window_roll = data_window[['product_id', 'count', 'sum']].groupby(['product_id']).rolling(offset).sum().drop('product_id', axis=1)
data_window_roll = data_window_roll.reset_index()
data_window_roll.columns = ['product_id', 'date', 'count_' + offset, 'sum_' + offset]
data_window_roll[['count_' + offset, 'sum_' + offset]] = data_window_roll[['count_' + offset, 'sum_' + offset]].shift(1)
data_window_roll.loc[data_window_roll['product_id']!=data_window_roll['product_id'].shift(1), ['count_' + offset, 'sum_' + offset]] = 0
data_window_roll['avg_' + offset] = data_window_roll['sum_' + offset]/data_window_roll['count_' + offset]
data = df_train.merge(data_window_roll, how='left', on=['product_id', 'date'])
data

We are typically left with a np.nan value for the first row of each group's avg_7D. Would you all recode this to zero, or leave it as nan and drop the row? Additionally, would you typically include several of these in your model? Say, compute 3D and a 7D offset average?

Separately, I take it you apply identical functions to the valid and test sets, as well, right?

Lastly, where/when I might learn more about similar courses that you might offer in the future?

Thank you for your time and consideration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant