2023-11-27

Use a Nonlinear Poisson Regression with two independent variables?

I'm looking for a way to use Nonlinear Regression with Poisson for predictive purposes. I would need something similar to Poisson regression, but with some modifications because:

  • I have two data sets that are made up of randomly placed numbers and have no correlation;
  • The two variables are both independent (and not one dependent and one independent);
  • The purpose of the regression will be to obtain a parameter that can be used in the Poisson distribution to calculate probabilities (explained better later), such as in poisson.pmf(2, regression_result);

Is there something i could use that satisfies the three points above? Any algorithm in some library like scikit learn, scipy, etc? I can't find an algorithm that is useful for my case. I would need something similar to sklearn.linear_model.PoissonRegressor, but for nonlinear regression and for both independent variables

My data are:

Team_A__goal_scored = [1, 3, 1, 2, 2] (x)
Team_B__goal_conceded = [3, 0, 1, 1, 2] (y)

WHAT DO I WANT TO GET? I need to find for the probability of Team A scoring exactly 2 goals to Team B, using Poisson distribution for example poisson.pmf(2, regression_result). As a lambda in the Poisson distribution, i will use the regression result​. I want to use regression for the purpose of relating team A's offense to team B's defense to find an ideal parameter to use in Poisson.

EXPLANATION: Team_A__goal_scored and Team_B__goal_conceded are the data of the last 5 rounds/matches played by the two teams against other opponents (Team A and Team B have never clashed). In the sixth round, the time will come for Team A and Team B to face each other and therefore I want to relate their data and calculate the probability that Team A scores 0 goals, 1 goal, 2 goals, 3 goals, etc. To be precise, i only need exactly 2 goals.

CLEAR SOMEONE'S DOUBT: Someone may say: "Why don't you directly use the Poisson distribution on the arithmetic mean of Team_A__goal_scored?" By doing this, I will have the probability that team A will score a certain number of goals, and it is a fair solution, but it is not what I want, because in this way the goals that team A scores will be calculated only ON THEMSELVES... and not related/influenced by the goals conceded by Team B in previous matches. I want to know how many goals Team A will score against Team B, considering the goals scored by Team A and also the Goals Conceded by Team B, because Team A's attack will be influenced by Team B's defense.

IMPORTANT EXAMPLE TO UNDERSTAND BETTER: I'll explain an example. If I have Team_A__goal_scored = [1, 3, 1, 2, 2] and Team_B__goal_conceded = [4, 5, 6, 5,4], it means Team B concedes a lot of goals.If instead Team_B__goal_conceded is [3, 0, 1, 1, 2], it means that team B concedes fewer goals and it will be more difficult for Team A to score goals for Team B. The goals that Team A will score, it will also be INFLUENCED by the goals that Team B concedes

I would like this final output:

The probability that Team A scores exactly 2 goals against Team B is: x %

UPDATE

I tried Poisson linear regression with one dependent variable and one independent variable. It's something similar to what I'm looking for, this is the one that comes closest to what I'm looking for, but obviously it's not good for the reasons stated above (lack of non-linearity and lack of two independent variables). The problem is that I can't find an algorithm that is useful for my case

import numpy as np
from sklearn.linear_model import PoissonRegressor

Team_A__goal_scored = np.array([1, 3, 1, 2, 2]).reshape(-1, 1)
Team_B__goal_conceded = np.array([3, 0, 1, 1, 2])

#Fit the model
clf = PoissonRegressor()
clf.fit(Team_A__goal_scored, Team_B__goal_conceded)

#Find the prediction (e.g. Team_A__goal_scored = 2)
lambda_pred = clf.predict(np.array([[2]]))[0]

#Poisson probability mass function to find the probability of scoring exactly 2 goals
from scipy.stats import poisson
probability_two_goals = poisson.pmf(2, lambda_pred)

print("Probability that team A scores exactly 2 goals against team B: ", probability_two_goals) 

Thank you



No comments:

Post a Comment