Skip to content

Commit

Permalink
fix: change names of period values so dummies work as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanbraun committed Jun 7, 2024
1 parent 66968ad commit 4c5631c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions code/07_05_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
cont_vars = ['dist', 'st_x', 'st_y', 'period_time_remaining', 'empty']
cat_vars = ['pos', 'hand', 'period']

# replace periods 1, 2, 3 ... with P1, P2, P3 ...
# this is so that when we turn them into dummy variables the column names are
# P1, P2, ... and not just 1, 2, which can cause issues
df['period'] = 'P' + df['period'].astype(str)

df_cat = pd.concat([pd.get_dummies(df[x]) for x in cat_vars], axis=1)

df_all = pd.concat([df[cont_vars], df_cat], axis=1)
Expand Down

0 comments on commit 4c5631c

Please sign in to comment.