lucasmaystre / choix

Inference algorithms for models based on Luce's choice axiom
MIT License
157 stars 27 forks source link

Bradley Terry Model #1

Closed seanlaw closed 7 years ago

seanlaw commented 7 years ago

I'd like to build a Bradley Terry model. Could you provide an example please?

tcloaa commented 7 years ago

Hi, I emailed the author and he replied to me with the following instructions:

You can fit a Bradley-Terry model as follows:

import choix
import numpy as np
n_items = 5

data = [(1, 0), (1, 4), (1, 2), (3,1), (2,3)]

# Infer Bradley-Terry model parameters.
est = choix.ilsr_pairwise(n_items, data, alpha=1e-5)

# Ranking of the items (from worst to best)
ranking = np.argsort(est)

Two comments.

1) By convention:

2) There are several functions that can compute the maximum-likelihood estimate. I recommend ilsr_pairwise, as it is the fastest one in general. But you might also want to try opt_pairwise with method="Newton-CG".

lucasmaystre commented 7 years ago

@tcloaa, thanks a lot for assisting. (Somehow I did not get notified of this issue.)

@seanlaw: I will soon release a few Jupyter notebooks with a few examples to get started with the library. Stay tuned!

lucasmaystre commented 7 years ago

FYI, I've just added two Jupyter notebooks that show how to use the library: