Bradley-Terry Model
Bradley-Terry model fitting via maximum likelihood.
The BT model assumes P(i beats j) = sigma(theta_i - theta_j) where sigma
is the logistic function. Fitting recovers the strength vector theta.
-
class winference.bradley_terry.BradleyTerry(models)[source]
Bases: object
Maximum-likelihood Bradley-Terry model.
- Parameters:
models (list[str]) – Unique model identifiers.
Examples
>>> bt = BradleyTerry(["A", "B", "C"])
>>> bt.fit(comparisons) # list of (i, j, outcome) tuples
>>> bt.win_probability("A", "B")
0.73
-
fit(comparisons, reg=0.0001)[source]
Fit the model from a list of (model_a, model_b, a_wins) triples.
- Parameters:
comparisons (list[tuple[str, str, bool]]) – Each element is (model_a, model_b, a_wins).
reg (float, default: 0.0001) – L2 regularisation strength (prevents divergence for unbeaten models).
- Return type:
Self
- Returns:
Self for method chaining.
-
win_probability(model_a, model_b)[source]
Predicted P(model_a beats model_b).
- Parameters:
-
- Return type:
float
-
win_probability_matrix()[source]
NxN matrix of predicted win probabilities.
- Return type:
ndarray[tuple[Any, ...], dtype[double]]
-
predicted_win_rates(comparisons)[source]
Return predicted P(a wins) for each comparison triple.
- Parameters:
comparisons (list[tuple[str, str, bool]])
- Return type:
ndarray[tuple[Any, ...], dtype[double]]
-
strengths()[source]
Return {model: theta} dictionary.
- Return type:
dict[str, float]
-
rank()[source]
Models sorted by decreasing strength.
- Return type:
list[str]
-
winference.bradley_terry.fit_bt_from_matrix(win_matrix, count_matrix, models, reg=0.0001)[source]
Convenience: fit BT from win/count matrices rather than triples.
- Parameters:
-
- Return type:
BradleyTerry