EconML
EconML copied to clipboard
Error message with LinearDML
The following estimation works fine:
est = LinearDML(model_y = LinearRegression()
, model_t = LogisticRegression()
, discrete_treatment = True, random_state = 123)
est.fit(y, T, X=None, W = W)
However if I don't specify the first stage models:
est = LinearDML(discrete_treatment = True, random_state = 123)
est.fit(y, T, X=None, W = W)
I get the following error message:
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (3, 10) + inhomogeneous part.
What version of econml are you using? Can you provide a repro including some dummy data? This works for me, both in econml 0.14.1 and in our new 0.15.0b1 beta:
import numpy as np
from econml.dml import LinearDML
Y = np.random.normal(size=1000)
T = np.random.choice(4, 1000)
W = np.random.normal(size=(1000, 3))
dml = LinearDML(discrete_treatment=True, random_state=123).fit(Y=Y, T=T, X=None, W=W)
Thanks for your reply. I am using econml 0.14.1 and your example works fine in my setting. I have removed from my dataset categories with too few observations and the LinearDML estimation is ok now. I could send you data if you want to assess more precisely where the error came from.