Skip to content

Commit

Permalink
changes for new season
Browse files Browse the repository at this point in the history
  • Loading branch information
ashharrison90 committed Aug 16, 2024
1 parent cdb1a85 commit 078d989
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
TRANSFER_URL = 'https://fantasy.premierleague.com/api/transfers/'

# Other constants
CURRENT_SEASON = '2023-24'
CURRENT_SEASON = '2024-25'
NUM_CHANGES = 0
TOTAL_GAMES_IN_SEASON = 38
DEFAULT_MODEL_PATH = 'model.pt'
Expand Down
Binary file modified model.pt
Binary file not shown.
14 changes: 11 additions & 3 deletions neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import os
import torch
import constants

logger = logging.getLogger()

Expand Down Expand Up @@ -103,7 +104,13 @@ def forward(self, x_categorical, x_numerical):
# calculate the categorical_embedding_size
for category in categorical_columns:
df[category] = df[category].astype('category')
categorical_column_sizes = [len(df[column].cat.categories) for column in categorical_columns]
categorical_column_sizes = [];
for column in categorical_columns:
# handle the case where the new season id is not in the data
if column == 'season_x' and constants.CURRENT_SEASON not in df[column].cat.categories:
categorical_column_sizes.append(len(df[column].cat.categories) + 1)
else:
categorical_column_sizes.append(len(df[column].cat.categories))
categorical_embedding_sizes = [(col_size, min(50, (col_size+1)//2)) for col_size in categorical_column_sizes]

# split the data 80/20 into training and test data
Expand Down Expand Up @@ -169,7 +176,8 @@ def get_season_id(season):
if value == season:
season_id = key
break
return season_id
# handle the case where the new season id is not in the data
return season_id if season_id is not None else len(season_dict)

# train the model
def train_model():
Expand Down Expand Up @@ -211,8 +219,8 @@ def predict_points(player_name, opposition_team_name, position, is_home, season,
player_id = get_player(player_name)
opposition_team_id = get_team(opposition_team_name)
position_id = get_position(position)
was_home = get_was_home(is_home)
season_id = get_season_id(season)
was_home = get_was_home(is_home)
categorical_data = torch.tensor([[player_id, opposition_team_id, position_id, season_id, was_home]], dtype=torch.int64)
numerical_data = torch.tensor([[parser.isoparse(kickoff_time).timestamp(), round, cost, gameweek]], dtype=torch.float)
return model(categorical_data, numerical_data).squeeze()
Expand Down

0 comments on commit 078d989

Please sign in to comment.