Last active
April 6, 2021 19:44
-
-
Save bkaankuguoglu/a8df9ee3a6b89d7c958854bee364efd9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generate_cyclical_features(df, col_name, period, start_num=0): | |
| kwargs = { | |
| f'sin_{col_name}' : lambda x: np.sin(2*np.pi*(df[col_name]-start_num)/period), | |
| f'cos_{col_name}' : lambda x: np.cos(2*np.pi*(df[col_name]-start_num)/period) | |
| } | |
| return df.assign(**kwargs).drop(columns=[col_name]) | |
| df_features = generate_cyclical_features(df_features, 'hour', 24, 0) | |
| # df_features = generate_cyclical_features(df_features, 'day_of_week', 7, 0) | |
| # df_features = generate_cyclical_features(df_features, 'month', 12, 1) | |
| # df_features = generate_cyclical_features(df_features, 'week_of_year', 52, 0) | |
| df_features |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment