I have a large datframe with two columns and a function that takes values from each rows and iterate over the dataframe. Below is the head of the dataframe.
xG_Team1 xG_Team2
0 1.440539 1.380095
1 2.123673 0.946116
2 1.819697 0.921660
3 1.132676 1.375717
4 1.244837 1.269933
x1, x2, x3 are constants.
x1 = [1,0,0]
x2 = [0,1,0]
x3 = [0,0,1]
For index 0,
y = np.array([1-(xG_Team1[0] + xG_Team2[0])/k, xG_Team1[0]/k, xG_Team2[0]/k])
i.e. y = np.array([1-(1.440539 + 1.380095)/k, 1.440539/k, 1.380095/k])
For index 1,
y = np.array([1-(xG_Team1[1] + xG_Team2[1])/k, xG_Team1[1]/k, xG_Team2[1]/k])
Where k is the total_timeslot and a constant.
total_timeslot = 180
Home_Goal = [] # No Goal
Away_Goal = [] # No Goal
def sum_squared_diff(x1, x2, x3, y):
ssd=[]
for k in range(total_timeslot):
if k in Home_Goal:
ssd.append( sum((x2 - y)**2))
elif k in Away_Goal:
ssd.append(sum((x3 - y)**2))
else:
ssd.append(sum((x1 - y)**2))
return ssd
y_0 = sum_squared_diff(x1, x2, x3, y)
The plan is to sum up the output from sum_squared_diff for all y.
Something like, for all i sum(y_i).
So for i = 0,
y_0 = sum_squared_diff(x1, x2, x3, y_0)
len(y_0) = 180
sum(y_0) = 0.0663099498972334
Then I will have n numbers of sum(y_i) for n xGs.
using @Dillon code, for the above datframe, n=5
sum(results.sum()) = 0.31885730707076826