解释器 Interpreter


YLearn 解释器为因果效应和策略估计提供了可解释性的树模型。它们分别是因果效应解释器 CEInterpreter 和策略估计解释器 PolicyInterpreter

CEInterpreter

对于由一个估计模型估计的CATE $\tau(v)$ ,比如,双机器学习模型,CEInterpreter 解释 由构建的一个用于建模 $\tau(v)$ 和谐变量 $v$ 之间关系的决策树得到的结果。然后能够使用拟合树模型的决策规则 来分析 $\tau(v)$。

PolicyInterpreter

PolicyInterpreter 能够被用于解释由一个实例 PolicyTree 返回的策略。通过给不同的样例分配不同的策略, 它的目标是最大化一个子群的因果效应并把它们与那些有负的因果效应的分开。

例子

我们构建了一个数据集,其中给定协变量 $v$ 和二元的治疗方案 $x$, 接受治疗的因果效应 $y$ 是正的如果 $v$ 的第一个纬度是正的,反之是负的。 PolicyInterpreter 的目标是帮助每个个体决定是否采取治疗,等价于因果效应是否是正的。


    import numpy as np
    from ylearn.utils import to_df

    # build dataset
    v = np.random.normal(size=(1000, 10))
    y = np.hstack([v[:, [0]] < 0, v[:, [0]] > 0])

    data = to_df(v=v)
    covariate = data.columns

    # train the `PolicyInterpreter`
    from ylearn.effect_interpreter.policy_interpreter import PolicyInterpreter
    pit = PolicyInterpreter(max_depth=2)
    pit.fit(data=data, est_model=None, covariate=covariate, effect_array=y.astype(float))

    pit_result = pit.interpret()
 

输出结果:


    >>> 06-02 17:06:49 I ylearn.p.policy_model.py 448 - Start building the policy tree with criterion PRegCriteria
    >>> 06-02 17:06:49 I ylearn.p.policy_model.py 464 - Building the policy tree with splitter BestSplitter
    >>> 06-02 17:06:49 I ylearn.p.policy_model.py 507 - Building the policy tree with builder DepthFirstTreeBuilder
     

查看推荐的个体策略:


    for i in range(57, 59):
        print(f'the policy for the sample {i}\n --------------\n' + pit_result[f'sample_{i}'] + '\n')
 

输出结果:

    
    >>> the policy for the sample 57
    >>> --------------
    >>> decision node 0: (covariate [57, 0] = -0.0948629081249237) <= 8.582111331634223e-05
    >>> decision node 1: (covariate [57, 8] = 1.044342041015625) > -2.3793461322784424
    >>> The recommended policy is treatment 0 with value 1.0

    >>> the policy for the sample 58
    >>> --------------
    >>> decision node 0: (covariate [58, 0] = 0.706959068775177) > 8.582111331634223e-05
    >>> decision node 4: (covariate [58, 5] = 0.9160318374633789) > -2.575441598892212
    >>> The recommended policy is treatment 1 with value 1.0