Why does introducing a different datatype to the logistic regression from the statsmodels api throw an error?

Viewed 35
X = pd.DataFrame([[True, 12.3], [False, 14.2], [True, 18.0]])
y = pd.Series([0, 1, 0])

log_reg = sm.Logit(y, X).fit()
log_reg.summary()

If I remove either the boolean or float variable it works.

However, when I leave them both in the, the following value error gets raised:

ValueError: Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).
1 Answers

You need to convert your variables into float variables:

sm.Logit(y, X.astype(float)).fit()

In your particular case the problem is the boolean variable. Maybe this statsmodels issue could be useful.

Related