Пример #1
0
def create_and_fit_team_model(df, df_X, teams=CURRENT_TEAMS, n_attempts=3):
    """
    Get the team-level stan model, which can give probabilities of
    each potential scoreline in a given fixture.
    """
    model_team = bpl.BPLModel(df, X=df_X)

    for i in range(n_attempts):
        print(f"attempt {i + 1} of {n_attempts}...", end=" ", flush=True)
        try:
            model_team.fit()
            print("SUCCESS!")
            break
        except RuntimeError:
            print("FAILED.")
            if i + 1 == n_attempts:
                raise
            else:
                continue

    # check if each team is known to the model, and if not, add it using FIFA rankings
    for team in teams:
        if team not in model_team.team_indices.keys():
            try:
                strvals = df_X.loc[(df_X["team"] == team),
                                   ["att", "mid", "defn", "ovr"]].values
                intvals = [int(v) for v in strvals[0]]
                model_team.add_new_team(team, intvals)
                print("Adding new team {} with covariates".format(team))
            except Exception:
                model_team.add_new_team(team)
                print("Adding new team {} without covariates".format(team))

    return model_team
Пример #2
0
def get_team_model(df, df_X):
    """
    Get the team-level stan model, which can give probabilities of
    each potential scoreline in a given fixture.
    """
    ## TEMP - GET NAN ERROR IF USE DF_X
    #    model_team = bpl.BPLModel(df, X=df_X)
    model_team = bpl.BPLModel(df, X=None)
    model_team.fit()
    return model_team
Пример #3
0
def create_and_fit_team_model(df, df_X, teams=CURRENT_TEAMS):
    """
    Get the team-level stan model, which can give probabilities of
    each potential scoreline in a given fixture.
    """
    model_team = bpl.BPLModel(df, X=df_X)

    model_team.fit()
    # check if each team is known to the model, and if not, add it using FIFA rankings
    for team in teams:
        if not team in model_team.team_indices.keys():
            try:
                strvals = df_X.loc[(df_X["team"] == team),
                                   ["att", "mid", "defn", "ovr"]].values
                intvals = [int(v) for v in strvals[0]]
                model_team.add_new_team(team, intvals)
                print("Adding new team {} with covariates".format(team))
            except:
                model_team.add_new_team(team)
                print("Adding new team {} without covariates".format(team))

    return model_team