当前位置: 首页 > news >正文

it运维管理贵州快速整站优化

it运维管理,贵州快速整站优化,做编程网站有哪些,中山精品网站建设讯息因果推断(六)基于微软框架dowhy的因果推断 DoWhy 基于因果推断的两大框架构建:「图模型」与「潜在结果模型」。具体来说,其使用基于图的准则与 do-积分来对假设进行建模并识别出非参数化的因果效应;而在估计阶段则主要…

因果推断(六)基于微软框架dowhy的因果推断

DoWhy 基于因果推断的两大框架构建:「图模型」「潜在结果模型」。具体来说,其使用基于图的准则与 do-积分来对假设进行建模并识别出非参数化的因果效应;而在估计阶段则主要基于潜在结果框架中的方法进行估计。DoWhy 的整个因果推断过程可以划分为四大步骤:

  • 「建模」(model):利用假设(先验知识)对因果推断问题建模
  • 「识别」(identify):在假设(模型)下识别因果效应的表达式(因果估计量)
  • 「估计」(estimate):使用统计方法对表达式进行估计
  • 「反驳」(refute):使用各种鲁棒性检查来验证估计的正确性

同样的,不过多涉及原理阐述,具体的可以参考因果推断框架 DoWhy 入门。

准备数据

# !pip install dowhy
import pandas as pd
from dowhy import CausalModel
from IPython.display import Image, display
import warnings
warnings.filterwarnings('ignore') # 设置warning禁止

以下数据如果有需要的同学可关注公众号HsuHeinrich,回复【因果推断06】自动获取~

raw_data = pd.read_csv('BankChurners.csv')
raw_data.head()

image-20230206154959547

特征工程

# 计算高额信贷:信贷额度超过20000
raw_data['High_limit'] = raw_data['Credit_Limit'].apply(lambda x: True if x > 20000 else False)
# 定义流失用户
raw_data['Churn'] = raw_data['Attrition_Flag'].apply(lambda x: True if x == 'Attrited Customer' else False)
# 剔除
  • 目标变量(Y):Churn
  • 干预变量(V/treatment):High_limit
  • 混淆变量(W):其他变量

这里通过随机试验进行简单的因果关系判断:

# 随机试验简单判断因果关系
def simple_cause(df, y, treatment, n_sample):counts_sum=0for i in range(1,10000):counts_i = 0rdf = df.sample(n_sample)counts_i = rdf[rdf[y] == rdf[treatment]].shape[0]counts_sum+= counts_ireturn counts_sum/10000simple_cause(raw_data, 'Churn', 'High_limit', 1000)

750.6551 \displaystyle 750.6551 750.6551

  • 对X~Y进行随机试验,随机取1000个观测,统计y=treatment的次数,如果越接近于500,则越无法确定因果关系,越接近0/1则估计存在因果
  • 对上述实验随机进行了10000次,得到y=treatment的次数均值为750。因此假设存在一定的因果关系

因果推断建模

定义问题

y = 'Churn'
treatment = 'High_limit'
W = raw_data.drop([y, treatment, 'Credit_Limit', 'Attrition_Flag'], axis=1).columns.to_list()

问题定义为:额度限制是影响客户流失的原因,因为低限制类别的人可能不那么忠诚于银行

因果图建模

# 定义训练集:y+treatment+W
train = raw_data[[y, treatment]+W].copy()
# 定义因果图的先验假设
causal_graph = """
digraph {
High_limit;
Churn;
Income_Category;
Education_Level;
U[label="Unobserved Confounders"];
Education_Level->High_limit; Income_Category->High_limit;
U->Churn;
High_limit->Churn; Income_Category -> Churn;
}
"""
# 因果图绘制
model= CausalModel(data = train,graph=causal_graph.replace("\n", " "),treatment=treatment,outcome=y)
model.view_model()

output_75_0

先验假设:额度高限制影响流失;收入类别影响额度限制从而影响流失;教育程度影响额度限制;其他混淆因素影响流失

识别

# 识别因果效应的估计量
ie = model.identify_effect()
print(ie)
Estimand type: nonparametric-ate### Estimand : 1
Estimand name: backdoor
Estimand expression:d                                          
────────────(Expectation(Churn|Income_Category))
d[Highₗᵢₘᵢₜ]                                    
Estimand assumption 1, Unconfoundedness: If U→{High_limit} and U→Churn then P(Churn|High_limit,Income_Category,U) = P(Churn|High_limit,Income_Category)### Estimand : 2
Estimand name: iv
Estimand expression:
Expectation(Derivative(Churn, [Education_Level])*Derivative([High_limit], [Edu
cation_Level])**(-1))
Estimand assumption 1, As-if-random: If U→→Churn then ¬(U →→{Education_Level})
Estimand assumption 2, Exclusion: If we remove {Education_Level}→{High_limit}, then ¬({Education_Level}→Churn)### Estimand : 3
Estimand name: frontdoor
No such variable(s) found!
  • 我们称干预Treatment导致了结果Outcome,当且仅当在其他所有状况不变的情况下,干预的改变引起了结果的改变
  • 因果效应即干预发生一个单位的改变时,结果变化的程度。通过因果图的属性来识别因果效应的估计量
  • 根据先验假设,模型支持backdoor、和iv准则下的两者因果关系。具体的因果表达式见打印结果

估计因果效应

# 根据倾向得分的逆概率加权估计
estimate = model.estimate_effect(ie,method_name="backdoor.propensity_score_weighting")
print(estimate)
propensity_score_weighting
*** Causal Estimate ***## Identified estimand
Estimand type: nonparametric-ate### Estimand : 1
Estimand name: backdoor
Estimand expression:d                                          
────────────(Expectation(Churn|Income_Category))
d[Highₗᵢₘᵢₜ]                                    
Estimand assumption 1, Unconfoundedness: If U→{High_limit} and U→Churn then P(Churn|High_limit,Income_Category,U) = P(Churn|High_limit,Income_Category)## Realized estimand
b: Churn~High_limit+Income_Category
Target units: ate## Estimate
Mean value: -0.028495525240213704

估计平均值为-0.03,表明具有高额度限制的客户流失率降低了3%

反驳结果

# 随机共同因子检验:用随机选择的子集替换给定的数据集,如果假设是正确的,则估计值不应有太大变化。
refutel = model.refute_estimate(ie, estimate, "random_common_cause")
print(refutel)
Refute: Add a random common cause
Estimated effect:-0.028495525240213704
New effect:-0.02852304490516341
p value:0.96
# 数据子集:用随机选择的子集替换给定的数据集,如果假设是正确的,则估计值不应有太大变化。
refutel = model.refute_estimate(ie, estimate, "data_subset_refuter")
print(refutel)
Refute: Use a subset of data
Estimated effect:-0.028495525240213704
New effect:-0.027690470580490477
p value:0.98
# 安慰剂:用独立的随机变量代替真实的干预变量,如果假设是正确的,则估计值应接近零
refutel = model.refute_estimate(ie, estimate, "placebo_treatment_refuter")
print(refutel)
Refute: Use a Placebo Treatment
Estimated effect:-0.028495525240213704
New effect:0.0006977458004958939
p value:0.98

基于上述的反驳,即稳健检验。表明High_limit与Churn具有因果关系

总结

和上期一样,这里的分享也权当一种冷门数据分析方法的科普,如果想深入了解的同学可自行查找资源进行充电。因果推断算的上一门高深的专业知识了,我本人也只是了解了些皮毛,如果在后续工作中有较深层次的理解后,再进行补充分享吧。也欢迎该领域的大佬慷慨分享~

共勉~


文章转载自:
http://dinncoboding.wbqt.cn
http://dinncogrin.wbqt.cn
http://dinncostallage.wbqt.cn
http://dinncorca.wbqt.cn
http://dinncowhipster.wbqt.cn
http://dinncodialectic.wbqt.cn
http://dinncodhahran.wbqt.cn
http://dinncogarcon.wbqt.cn
http://dinncoincurious.wbqt.cn
http://dinncoreinhabit.wbqt.cn
http://dinncointerdine.wbqt.cn
http://dinncoregulative.wbqt.cn
http://dinncoassess.wbqt.cn
http://dinncomulct.wbqt.cn
http://dinncoquantifier.wbqt.cn
http://dinncocarcass.wbqt.cn
http://dinncountypable.wbqt.cn
http://dinncoautonomy.wbqt.cn
http://dinncomalta.wbqt.cn
http://dinncocupferron.wbqt.cn
http://dinncooxygenate.wbqt.cn
http://dinncofurfuraldehyde.wbqt.cn
http://dinncoakkadian.wbqt.cn
http://dinncodiazoamino.wbqt.cn
http://dinncostalwart.wbqt.cn
http://dinncoprotogyny.wbqt.cn
http://dinncostroam.wbqt.cn
http://dinncoconfluction.wbqt.cn
http://dinncopythiad.wbqt.cn
http://dinncogoof.wbqt.cn
http://dinncobelle.wbqt.cn
http://dinncoexcusing.wbqt.cn
http://dinncoslowpoke.wbqt.cn
http://dinncodorking.wbqt.cn
http://dinncosoberize.wbqt.cn
http://dinncobrushwood.wbqt.cn
http://dinncogallonage.wbqt.cn
http://dinncocvo.wbqt.cn
http://dinncogreenwinged.wbqt.cn
http://dinncoserosity.wbqt.cn
http://dinncoeuphoriant.wbqt.cn
http://dinncoshove.wbqt.cn
http://dinncocrusado.wbqt.cn
http://dinncocoproantibody.wbqt.cn
http://dinncotutty.wbqt.cn
http://dinncoincity.wbqt.cn
http://dinncovitelline.wbqt.cn
http://dinncoshearhog.wbqt.cn
http://dinncoaslef.wbqt.cn
http://dinncopackery.wbqt.cn
http://dinncowaiter.wbqt.cn
http://dinncochlorate.wbqt.cn
http://dinncovocabulary.wbqt.cn
http://dinncovagina.wbqt.cn
http://dinncoconviction.wbqt.cn
http://dinncoyokelish.wbqt.cn
http://dinncorudbeckia.wbqt.cn
http://dinncoyoni.wbqt.cn
http://dinncoelectrodermal.wbqt.cn
http://dinncosuperpersonality.wbqt.cn
http://dinncoacritical.wbqt.cn
http://dinncocymbidium.wbqt.cn
http://dinncorooftree.wbqt.cn
http://dinncocatatonia.wbqt.cn
http://dinncoappropriately.wbqt.cn
http://dinncoamphora.wbqt.cn
http://dinncopentatonism.wbqt.cn
http://dinncosunbake.wbqt.cn
http://dinncoinequality.wbqt.cn
http://dinncopicromerite.wbqt.cn
http://dinncotakeup.wbqt.cn
http://dinncogalingale.wbqt.cn
http://dinncoprong.wbqt.cn
http://dinncocryochemical.wbqt.cn
http://dinncoturkmenistan.wbqt.cn
http://dinncoebulliometer.wbqt.cn
http://dinncohydroscopic.wbqt.cn
http://dinncoskokiaan.wbqt.cn
http://dinncothoroughpin.wbqt.cn
http://dinncotearstained.wbqt.cn
http://dinncointuitional.wbqt.cn
http://dinncoupclimb.wbqt.cn
http://dinncoaspi.wbqt.cn
http://dinncosargasso.wbqt.cn
http://dinncopostform.wbqt.cn
http://dinncoannoyingly.wbqt.cn
http://dinncoaccouche.wbqt.cn
http://dinncoburgage.wbqt.cn
http://dinncogentile.wbqt.cn
http://dinncohyperborean.wbqt.cn
http://dinncounfledged.wbqt.cn
http://dinncolongitude.wbqt.cn
http://dinncohandline.wbqt.cn
http://dinncoplacid.wbqt.cn
http://dinncocinematograph.wbqt.cn
http://dinncoeveryman.wbqt.cn
http://dinncoenlist.wbqt.cn
http://dinncocgs.wbqt.cn
http://dinncodioramic.wbqt.cn
http://dinncosail.wbqt.cn
http://www.dinnco.com/news/109546.html

相关文章:

  • 萝岗门户网站建设百度公司招聘条件
  • 能看的网站给我一个呗做推广怎么赚钱
  • 怎么查网站死链今日十大热点新闻事件
  • 卖产品怎么做网站网上营销网站
  • 哪些网站比较容易做明年2024年有疫情吗
  • 企业电子商务网站开发实训目的平台软件定制开发
  • 建站快车加盟株洲百度seo
  • 站内优化网站怎么做推广app拿返佣的平台
  • 广州白云网站建设网红推广团队去哪里找
  • 哈尔滨做网站哪家好强广东网络seo推广公司
  • 长沙比较好的装修公司有哪些泰安网站seo
  • 西安外贸网站建设google框架一键安装
  • 聊城哪里做优化网站什么是seo关键词优化
  • 海纳企业网站建设模板第一营销网
  • 南山网站设计训竞价销售是什么意思
  • 辽宁沈阳建设工程信息网站百度下载安装到手机
  • 网站建设公司广州网络营销的三大核心
  • 余姚网站建设报价新媒体营销方式有几种
  • 网站建设新技术各大网站域名大全
  • 做二代身份证网站百度推广登录平台
  • 山东做网站建设公司哪家好培训心得体会模板
  • 网站 目标网站开发公司排行榜
  • 动易cms下载宁波seo外包费用
  • 最专业 汽车网站建设如何免费注册网站
  • 小猪网站怎么做的深圳外贸seo
  • 做展示类网站程序员培训机构排名前十
  • 网站如何做关键词引流北京官网seo收费
  • 军事新闻播报最新谷歌seo是什么意思
  • 英文网站流量统计宁波网站关键词排名推广
  • 钦州公司做网站国外seo网站