Implementing a Conditional Logit in Python StatsModels I have a dataframe with some horseracing data, and each row contains a predicted speed rating for each of the runners. I am now trying to convert that information into a winning probability for each runner in a given race. I have tried implementing a softmax by group, but it tends to produce extreme results for the favored horse and is not well-calibrated to actual observed results. Much of the academic literature on the topic suggests using a conditional logit model for such a problem, but my attempts to implement it have thrown a variety of errors.
A simplified example of the dataframe that would be used to fit the conditional logit is below. The goal is to create a new column that provides a winning probability based on just the speed rating, conditional on the speed ratings of the other runners in the race.




Race
Runner
Proj. Speed Rating
Winner?




1012
Horse 1
87.25
0


1012
Horse 2
86.52
0


1012
Horse 3
77.56
0


1012
Horse 4
84.25
1


1013
Horse 1
77.55
0


1013
Horse 3
74.06
0


1013
Horse 5
74.59
1


1013
Horse 7
74.46
0




My code thus far is as follows:
from statsmodels.discrete.conditional_models import ConditionalLogit

labels =  df['Winner?']
pred = df['Proj. Speed Rating']
groups = df['Race']

cl_model = ConditionalLogit(endog = labels, exog = pred,groups = group)
cl_fit = cl_model.fit()
cl_pred = cl_fit.predict(pred_external,race_external)


However no matter which adjustments I make the 'predict' line continues to throw a value error - in the format above it's 'Truth Value is ambiguous', and if I add the 'exog =' and 'groups =' it's a "NotImplemented" error. So my question is twofold: 1.) am I correct in thinking a conditional logit is the best way to approach this problem, even with only 1 independent variable? 2.) If so, how can I fix my code above to generate race-level probability estimates?
I don't have a statistics or computer science background, so any assistance with this is greatly appreciated.

I don't see anything obviously wrong and the approach appears sound.  The simple simulation below emulates what you are doing and runs fine for me.  Note that if you construct and fit the model in separate steps, you can see whether the ValueError occurs during setup or during optimization.
from statsmodels.discrete.conditional_models import ConditionalLogit
import numpy as np

g = np.kron(np.arange(100), np.ones(5)).astype(int)
x = np.random.normal(size=500)
pr = 1 / (1 + np.exp(-x))
y = (np.random.uniform(size=500) < pr).astype(int)

m = ConditionalLogit(endog=y, exog=x, groups=g)
r = m.fit()

Can you send the complete text of the ValueError?  Also, check the dtypes of the three variables, perhaps one of them is a string or object?
