我可以在這方面使用一些幫助。我想在 python 中為任意數量的球隊模擬足球聯賽,并在表格中計算一個賽季的積分。規則很簡單:
- 聯盟中的每支球隊都會互相交手兩次。所以每支球隊打 2*(Nteams_in_league -1)
- 球隊有 50% 的獲勝機會。
- 只有兩種可能的結果,贏或輸。
- 勝一場得3分,負一場得0分。
這是我在 11 個賽季的 8 支球隊的聯賽中尋找的輸出示例。它基于我所做的嘗試,但并不完全正確,因為它沒有正確地在贏家和輸家之間分配分數。
列 = 季節,行 = 團隊,觀察是積分。
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 57 | 51 | 66 | 54 | 60 | 51 | 57 | 54 | 45 | 72 |
| 2 | 51 | 51 | 42 | 51 | 66 | 60 | 63 | 60 | 81 | 63 |
| 3 | 51 | 69 | 51 | 48 | 36 | 48 | 57 | 54 | 48 | 60 |
| 4 | 54 | 57 | 66 | 54 | 75 | 60 | 60 | 66 | 69 | 42 |
| 5 | 72 | 57 | 63 | 57 | 60 | 54 | 48 | 66 | 54 | 42 |
| 6 | 54 | 45 | 54 | 45 | 60 | 57 | 51 | 60 | 66 | 51 |
| 7 | 51 | 63 | 72 | 63 | 63 | 54 | 60 | 63 | 54 | 66 |
| 8 | 66 | 57 | 42 | 57 | 51 | 57 | 51 | 75 | 72 | 60 |
uj5u.com熱心網友回復:
這是一種方法。這獨立地模擬了每個季節。對于每個賽季和每對球隊,我們模擬兩場比賽的兩個結果,假設每支球隊都有 50% 的獲勝機會。
import numpy as np
import pandas as pd
from itertools import combinations
def simulate_naive(n_teams):
'Simulate a single season'
scores = np.zeros(n_teams, dtype=int)
for i, j in combinations(range(n_teams), 2):
# each pair of teams play twice, each time with 50/50 chance of
# either team winning; the winning team gets three points
scores[i if np.random.rand() < 0.5 else j] = 3
scores[i if np.random.rand() < 0.5 else j] = 3
return scores
n_teams = 8
n_seasons = 10
df = pd.DataFrame({season: simulate_naive(n_teams) for season in range(n_seasons)})
print(df)
# 0 1 2 3 4 5 6 7 8 9
# 0 15 30 21 12 24 24 9 21 18 33
# 1 21 18 24 24 15 21 12 30 18 21
# 2 21 27 21 18 21 27 27 15 12 24
# 3 27 12 9 36 18 12 30 15 24 21
# 4 24 24 27 24 18 18 33 18 30 15
# 5 18 15 21 15 15 27 15 24 24 15
# 6 18 18 30 21 33 21 24 27 18 21
# 7 24 24 15 18 24 18 18 18 24 18
我想知道是否有更好的統計方法可以避免模擬每場比賽。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/411461.html
標籤:
下一篇:為什么回圈將NA值添加到資料幀?
