R包synthpop的Python实现

py-synthpop的Python项目详细描述


合成器

R package synthpop的Python实现。在

synthpop的R实现是一个工具,用于生成包含机密信息的微数据的合成版本,以便安全地发布给用户进行探索性分析。生成合成数据的关键目标是用合成的原始值替换敏感的原始值,从而使数据集中包含的统计信息失真最小。变量可以是分类的,也可以是连续的,使用序列建模方法逐一综合。替换是通过使用参数化或分类和回归树模型从与原始数据拟合的条件分布中提取来生成的。在

{{1}在cd1>之后,通过cd1}方法生成的原始数据。如果使用默认设置,或者使用用户定义的方法,这个过程可以很大程度上实现自动化。可选参数可以用来影响披露风险和合成数据的分析质量。在

发展现状和路线图

此项目处于Alpha状态,可以在here找到路线图。在

安装

pip

pip install py-synthpop

来源

^{pr2}$

示例

成人数据集

我们将使用US adult census dataset,这是从美国人口普查局数据库中提取的免费开放数据集。数据集最初是为二元分类问题设计的,任务是预测一个人的年收入是否超过5万美元。数据集是离散和连续特征的混合体,包括年龄、工作状态(工人阶级)、教育程度、婚姻状况、种族、性别、关系和每周工作时间。在

In[1]:fromdatasets.adultimportdfIn[2]:df.head()Out[2]:ageworkclassfnlwgteducationeducational-nummarital-statusoccupationrelationshipracegendercapital-gaincapital-losshours-per-weeknative-countryincome039State-gov77516Bachelors13Never-marriedAdm-clericalNot-in-familyWhiteMale2174040United-States<=50K150Self-emp-not-inc83311Bachelors13Married-civ-spouseExec-managerialHusbandWhiteMale0013United-States<=50K238Private215646HS-grad9DivorcedHandlers-cleanersNot-in-familyWhiteMale0040United-States<=50K353Private23472111th7Married-civ-spouseHandlers-cleanersHusbandBlackMale0040United-States<=50K428Private338409Bachelors13Married-civ-spouseProf-specialtyWifeBlackFemale0040Cuba<=50K

合成器

  1. 对成人数据集使用默认参数:
In[1]:fromsynthpopimportSynthpopIn[2]:fromdatasets.adultimportdf,dtypesIn[3]:spop=Synthpop()In[4]:spop.fit(df,dtypes)train_agetrain_workclasstrain_fnlwgttrain_educationtrain_educational-numtrain_marital-statustrain_occupationtrain_relationshiptrain_racetrain_gendertrain_capital-gaintrain_capital-losstrain_hours-per-weektrain_native-countrytrain_incomeIn[5]:synth_df=spop.generate(len(df))generate_agegenerate_workclassgenerate_fnlwgtgenerate_educationgenerate_educational-numgenerate_marital-statusgenerate_occupationgenerate_relationshipgenerate_racegenerate_gendergenerate_capital-gaingenerate_capital-lossgenerate_hours-per-weekgenerate_native-countrygenerate_incomeIn[6]:synth_df.head()Out[6]:ageworkclassfnlwgteducationeducational-nummarital-statusoccupationrelationshipracegendercapital-gaincapital-losshours-per-weeknative-countryincome021?21305511th7Never-married?Not-in-familyOtherFemale0030United-States<=50K123Private150683HS-grad9Never-marriedAdm-clericalNot-in-familyWhiteFemale0040United-States<=50K261Private19141710th6WidowedSalesNot-in-familyBlackFemale0032United-States<=50K350Private190762HS-grad9DivorcedSalesNot-in-familyWhiteMale0060United-States<=50K442Local-gov255675HS-grad9Married-civ-spouseOther-serviceHusbandBlackMale0040United-States<=50KIn[7]:spop.methodOut[7]:agesampleworkclasscartfnlwgtcarteducationcarteducational-numcartmarital-statuscartoccupationcartrelationshipcartracecartgendercartcapital-gaincartcapital-losscarthours-per-weekcartnative-countrycartincomecartdtype:objectIn[8]:spop.visit_sequenceOut[8]:age0workclass1fnlwgt2education3educational-num4marital-status5occupation6relationship7race8gender9capital-gain10capital-loss11hours-per-week12native-country13income14dtype:int64In[9]:spop.predictor_matrixOut[9]:ageworkclassfnlwgteducationeducational-nummarital-statusoccupationrelationshipracegendercapital-gaincapital-losshours-per-weeknative-countryincomeage000000000000000workclass100000000000000fnlwgt110000000000000education111000000000000educational-num111100000000000marital-status111110000000000occupation111111000000000relationship111111100000000race111111110000000gender111111111000000capital-gain111111111100000capital-loss111111111110000hours-per-week111111111111000native-country111111111111100income111111111111110
  1. 定义成人数据集的访问顺序:
In[1]:fromsynthpopimportSynthpopIn[2]:fromdatasets.adultimportdf,dtypesIn[3]:spop=Synthpop(visit_sequence=[0,1,5,3,2])In[4]:spop.fit(df,dtypes)train_agetrain_workclasstrain_marital-statustrain_educationtrain_fnlwgtIn[5]:synth_df=spop.generate(len(df))generate_agegenerate_workclassgenerate_marital-statusgenerate_educationgenerate_fnlwgtIn[6]:synth_df.head()Out[6]:ageworkclassfnlwgteducationmarital-status057Self-emp-not-inc327901Prof-schoolMarried-civ-spouse124Private34568Assoc-vocNever-married250Private256861HS-gradMarried-civ-spouse328Private186239Some-collegeNever-married438Private216129BachelorsDivorcedIn[7]:spop.methodOut[7]:agesampleworkclasscartfnlwgtcarteducationcarteducational-numcartmarital-statuscartoccupationcartrelationshipcartracecartgendercartcapital-gaincartcapital-losscarthours-per-weekcartnative-countrycartincomecartdtype:objectIn[8]:spop.visit_sequenceOut[8]:age0workclass1fnlwgt4education3marital-status2dtype:int64In[9]:spop.predictor_matrixOut[9]:ageworkclassfnlwgteducationmarital-statusage00000workclass10000fnlwgt11011education11001marital-status11000

许可证

这个项目正在Hazy Limited开发,并在MIT license下发布。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
swing如何在不使用BorderLayout的情况下将组件居中放置在JPanel中?JAVA   java行话游戏向gridlayout添加输入   如何在Java中检索数组中列表的第一个和第二个元素?   在IDEA 12.1中调试Java Spring项目时,Jetty server为什么会挂起?   java我的循环没有在屏幕上显示任何内容   Protostuff 1.3.8中的java RuntimeSchema   java Android Realm RecyclerView动画不工作?   java在主活动中创建类   java如何在OData 4中实现三段或更多段导航   java TreeCellEditor:即使ShouldSelectCell返回false,也必须选择要编辑的单元格   java Tomcat安全权限错误   java通过split()解析文件名以比较两个常用字段   Java数组排序不起作用   使用Java创建带多个项目的签出会话   java有没有办法在安卓上,在我自己的应用程序中使用本机消息传递应用程序?   java Hibernate多个关系和一个附加表   java格式化TableView列中的ObjectProperty<LocalDateTime>   带有原子替换的java线程安全可序列化集合