小能豆

How to use Bayesian Optimization (or similar Bayesian package), in Python, to find the optimal parameter to use in Poisson?

py

I would like to divide Team A's attack by Team B's defense, and then use the Poisson parameter to calculate how many goals Team A can score against Team B.

The problem is that the result of the division is too small a number (0.77) to use in Poisson to obtain a sufficient result. So it was suggested to me to use Bayesian Optimization or other methods from the Bayesian software package (Bayesian inference or other different ones). I’ve never used Bayesian packets and I’m trying to understand them, so sorry. Below, i tried to sketch some code with Bayesian Optimization, but I don’t think it’s correct. In case Bayesian Optimization is not for me, I hope someone can suggest me what i should use.

Anyway these are my data:

Total data relating to 5 games played:

        TEAM_A__List_Goals_Scored = [2, 1, 3, 0, 1]
        TEAM_A__Total_Goals_Scored = 7
        TEAM_A__Number_Match_Played = 5
        TEAM_A__Average_Scored = 1.40

        TEAM_B__List_Goals_Conceded = [1, 2, 2, 3, 1]
        TEAM_B__Total_Goals_Conceded = 9
        TEAM_B__Number_Match_Played = 5
        TEAM_B__Average_Conceded = 1.8

PREMISES

Initially I was thinking of proceeding with:

 TEAM_A__Total_Goals_Scored / TEAM_B__Total_Goals_Conceded #7/9=0.77

However 0.77 is a rather low/small number to use in a Poisson distribution:

    from scipy.stats import poisson
    poisson.pmf(1, 0.77)
    poisson.pmf(2, 0.77)
    poisson.pmf(3, 0.77)

So I thought I’d intervene somehow on 0.77 or on TEAM_A__List_Goals_Scored = [2, 1, 3, 0, 1] and TEAM_B__List_Goals_Conceded = [1, 2, 2, 3, 1]

MY BAYESIAN OPTIMIZER CODE

I tried using this bayesian-optimization/BayesianOptimization from Github, but maybe there are others that are better.

 from bayes_opt import BayesianOptimization

 TEAM_A__List_Goals_Scored = [2, 1, 3, 0, 1]
 TEAM_B__List_Goals_Conceded = [1, 2, 2, 3, 1]

 # Bounded region of parameter space
 pbounds = {'x': TEAM_A__List_Goals_Scored, 'y': TEAM_B__List_Goals_Conceded}

 optimizer = BayesianOptimization(
     f=black_box_function,
     pbounds=pbounds,
     random_state=1,
 )

 # Maximization
 optimizer.maximize(
     #Random exploration steps you want to take
     init_points=2,

     #Bayesian optimization steps you want to perform
     n_iter=3,
 )

But as you can see it presents some problems, because I have never used it so far, and I can’t get the parameter I’m looking for (which I will then use in Poisson). Could someone help me please? Also, if Bayesian Optimizer isn’t right for what I’m looking for, what do you recommend I use? Thank you


阅读 88

收藏
2023-11-24

共1个答案

小能豆

If I understand correctly, you want to optimize a parameter (let’s call it lambda) for the Poisson distribution based on the division of TEAM_A__Total_Goals_Scored by TEAM_B__Total_Goals_Conceded. Bayesian optimization is a valid approach for this type of problem.

Here’s how you can use Bayesian optimization to find the optimal lambda:

from bayes_opt import BayesianOptimization
from scipy.stats import poisson
import numpy as np

# Given data
TEAM_A__Total_Goals_Scored = 7
TEAM_B__Total_Goals_Conceded = 9

# Define the objective function
def objective(x):
    lambda_param = x['lambda']

    # Calculate the Poisson probabilities for goals 0 to 10 (you can adjust the range)
    poisson_probs = [poisson.pmf(i, lambda_param) for i in range(11)]

    # Assume you want to maximize the probability of scoring at least TEAM_A__Total_Goals_Scored
    return -np.sum(poisson_probs[:TEAM_A__Total_Goals_Scored])

# Bounded region of parameter space
pbounds = {'lambda': (0.01, 10)}  # Adjust the range based on your problem

# Initialize BayesianOptimization
optimizer = BayesianOptimization(
    f=objective,
    pbounds=pbounds,
    random_state=1,
)

# Perform the optimization
optimizer.maximize(
    # Random exploration steps you want to take
    init_points=5,
    # Bayesian optimization steps you want to perform
    n_iter=10,
)

# Get the optimal value for lambda
optimal_lambda = optimizer.max['params']['lambda']
print(f'Optimal lambda: {optimal_lambda}')

This script defines an objective function based on the Poisson distribution and uses Bayesian optimization to find the optimal value for the lambda parameter. You can adjust the bounds and other parameters according to your problem.

Keep in mind that this is a simplified example, and you might need to customize the objective function based on your specific use case and requirements. Also, the optimal value for lambda obtained through Bayesian optimization is just a recommendation; you may need to round or adjust it based on your specific needs.

2023-11-24