【问题标题】:"Perfect separation" error when using Matcher from pymatch (Propensity score matching)从 pymatch 使用 Matcher 时出现“完美分离”错误(倾向得分匹配)
【发布时间】:2019-06-27 07:37:26
【问题描述】:

我正在尝试使用 pymatch 包,但我不断收到错误 Error: Perfect separation detected, results not available。我检查了多次,我的数据集不相等。它包含 260k 行用于控制和 50k 用于处理,并且具有不同的平均值。我只有 5 个变量,所有 integersFloats 都舍入到小数点后 2 位。

我的目标是将一些经过处理的客户与未处理的客户进行匹配,以便根据倾向得分匹配进行进一步分析。

我已经删除了异常值,因为它显然不能很好地处理这些。我还在逗号后将小数四舍五入到 2 个位置。我尝试只使用整个数据集的 2 个变量。没有任何效果。

d = {'Customer': ['A','B','C','D'], 'Basket_Size': [30, 40,25,30], 'Miles_away': [5.2, 15.4,16.3,7.2], 'was_treated': [1, 0,0,1]}
df = pd.DataFrame(data=d)
df

test = df[df.was_treated== 1]
control = df[df.was_treated== 0]

m = Matcher(test, control, yvar="was_treated", exclude=['Customer'])
## until here it runs perfectly fine

# output:

#Formula:
#was_treated~ Basket_Size+Miles_away
#n majority: 2
#n minority: 2


## this now throws the error
np.random.seed(20170925)
m.fit_scores(balance=True, nmodels=20)

# output: 
# Error: Perfect separation detected, results not available
# Fitting Models on Balanced Samples: 1\20

我希望得到像 Average Accuracy: 78% 这样的输出,但我得到 Average Accuracy: nan% 和错误 Error: Perfect separation detected, results not available

【问题讨论】:

    标签: python matching propensity-score-matching


    【解决方案1】:

    我自己解决了这个问题。根据数据的性质,一个variable 受到了治疗的影响。这意味着was_treated== 1 中的任何数据点都不能有Miles_away >10,反之亦然,was_treated== 0 中的任何数据点都不能有Miles_away <10。这是完美的分离。从倾向评分中排除这个variable 解决了这个问题。

    
        m = Matcher(test, control, yvar="fast_delivery", exclude=['CUSTOMER_NUMBER','Miles_away'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 2021-06-06
      • 2021-04-10
      • 1970-01-01
      相关资源
      最近更新 更多