Closed yanduoduan closed 1 year ago
PolicyInterpreter.decide()
was added in the main branch which is not released yet. Upgrade YLearn from latest source code to run latest case study please.
hi,There is one control and several treatment, I want to build the model through casual tree, the code shows an error, what is the problem? x = [[0,0.31388521, -1.0856306], [1,0.35388521, -11.0856306], [2,1.715597, -1.03306], [1,1.840204, -1.0506], [2,1.144243, -1.0876], [0,0.282745, -1.0806], [0,0.31388521, -4.046], [0,0.21388521, -1.3997345], [1,0.11388521, -2.0856306], [2,0.1388521, -1.0856306]] outcome = 'outcome' treatment = 'treatment' data = pd.DataFrame(x,columns=['treatment','outcome','v_0']) adjustment = data.columns[2:] ct = CausalTree(min_samples_leaf=3, max_depth=5) ct.fit(data=data, outcome=outcome, treatment=treatment, adjustment=adjustment,treat=[1,2],control=0)
Hi,
The error is due to that the parameter treat
is given a wrong value [1, 2]
when calling fit()
. It should be either treat=1
or treat=2
.
I further explain this issue as follows.
Curretnly CausalTree
only supports binary treatment problems. That means when a treatment variable (call it T
) has several different possible values (e.g., T=0, 1, 2), CausalTree
will first convert this problem into a binary one, e.g., T=0
is the control while T=2
is the treat by specifiying the parameters treat=2
and control=0
when calling the fit()
method. The fitted CausalTree
will be able to estimate the causal effects of T=2
against T=0
.
In this sense, I think your question is actually "There is one control and several treatment values for a single treatment variable".
When should one set the parameter treat
as a list of different values? The answer is when there are several treatment variables.
For an example, there are two treatment variables T_1
with possible values 0, 1, 2, 3
and T_2
with possible values 0, 1
. Suppose that we take those data with T_1=0
and T_2=0
as the control group while take those data with T_1=3
and T_2=1
as the treat group, then when calling the fit()
method we should set treat=[3, 1]
and control=[0, 0]
.
hi,I understand the problem.If my example above does not specify treat and control, how the causal tree is handled?
If the treat
and control
are not given, then CausalTree
will first apply an OrdinalEncoder
transformer to the treatment variable which will be transformed into an array of integers. After that, CausalTree
will implicitly set treat
as 1 and control
as 0.
That said, treat=1
and control=0
implicitly in your example if they are not specified.
Here we assume that the OrdinalEncoder
will transform 1
into 1
and 0
into 0
.
AttributeError: 'PolicyInterpreter' object has no attribute 'decide',why?