python中的插补方法

autoimpute的Python项目详细描述


自动输入徽标pypi version构建状态documentation statusmit licensepython 3.6+

autoimpute是一个用于分析和实现插补方法的python包!

查看我们的网站以了解更详细的自动输入。

查看我们的文档以获取《开发人员指南》自动输入

安装

  • 自动输入现在已注册到PYPI!使用pip install autoimpute下载
  • 最新版本的自动输入是0.11.4
  • 如果pip缓存了旧版本,请尝试pip install--no cache dir--upgrade autoimpute
  • 如果要使用开发分支,请使用以下脚本:

开发

git clone -b dev --single-branch https://github.com/kearnz/autoimpute.git
cd autoimpute
python setup.py install

动机

大多数机器学习算法期望干净完整的数据集,但现实世界中的数据是混乱和缺失的。不幸的是,处理丢失的数据相当复杂,所以编程语言通常将此责任推给最终用户。默认情况下,r会删除所有缺少数据的记录,这种方法易于实现,但在实践中常常会出现问题。对于更丰富的插补策略,r有多个包来处理丢失的数据(MICEAMELIAtsimpute,等等)。python用户并没有这么幸运。当最终用户在缺少记录的数据集上部署模型时,python的scikit learn会抛出一个运行时错误,并且几乎没有第三方包可以处理端到端的插补。

因此,该包通过提供更清晰的插补过程、使插补方法更易访问以及测量插补方法在监督回归和分类中的影响来帮助python用户。在这样做的过程中,这个包将丢失的数据插补方法带到python世界中,并使它们在python机器学习中很好地工作。g项目(特别是利用scikit learn的项目)。最后,这个包提供了自己的有监督机器学习方法的实现,这些方法将scikit learn和statsmodels扩展到多个输入数据集。

主要功能

  • 实用函数,用于检查缺失数据中的模式并确定相关的插补特征
  • 缺失分类器和自动缺失数据测试集生成器
  • 分类变量的本地处理(作为预测和插补目标)
  • pandasdataframes
  • 的单个和多个插补类
  • 对实用函数和插补方法的自定义可视化支持
  • 使用多输入数据集的分析方法和混合参数推断
  • 下表规定了多种插补方法:

支持的插补方法

<表><广告>单变量 多变量时间序列/插值 < /广告><正文>平均值线性回归 线性中间值二项logistic回归 二次型模式多项式logistic回归 立方随机随机回归 多项式标准值贝叶斯线性回归 样条曲线分类 贝叶斯二元逻辑回归 时间加权预测平均匹配下一个OBS结转局部剩余绘制最后结转的OBS

待办事项

  • 其他横截面方法,包括随机森林、knn、em和最大似然
  • 其他时间序列方法,包括ewma、arima、kalman滤波器和状态空间模型
  • 对缺失数据模式、插补方法和分析模型可视化的扩展支持
  • 对多重插补后的分析指标和分析模型的额外支持
  • 对更大数据集的多处理和gpu支持,以及与daskdataframes
  • 的集成

示例用法

自动输入设计为用户友好和灵活。在执行插补时,自动插补直接适用于scikit learn机器学习项目。输入源继承自sklearn的baseestimatortransformerminxin并实现fittransform方法,使它们成为sklearn管道中的有效转换器。

现在,我们将使用两个输入程序类:

fromautoimpute.imputationsimportSingleImputer,MultipleImputersi=SingleImputer()# imputation methods, passing through the data oncemi=MultipleImputer()# imputation methods, passing through the data multiple times

估算可以简单到:

# simple example using default instance of MultipleImputerimp=MultipleImputer()# fit transform returns a generator by default, calculating each imputation method lazilyimp.fit_transform(data)

或相当复杂,例如:

# create a complex instance of the MultipleImputer# Here, we specify strategies by column and predictors for each column# We also specify what additional arguments any `pmm` strategies should takeimp=MultipleImputer(n=10,strategy={"salary":"pmm","gender":"bayesian binary logistic","age":"norm"},predictors={"salary":"all","gender":["salary","education","weight"]},imp_kwgs={"pmm":{"fill_value":"random"}},visit="left-to-right",return_list=True)# Because we set return_list=True, imputations are done all at once, not evaluated lazily.# This will return M*N, where M is the number of imputations and N is the size of original dataframe.imp.fit_transform(data)

autoimpute还将有监督的机器学习方法从scikit learnstatsmodels扩展到将它们应用于多个输入数据集(使用引擎盖下的multipleimputer)。目前,自输入支持线性回归和二元逻辑回归。目前正在开发其他监督方法。

与输入法一样,自动输入法的分析方法可以简单也可以复杂:

fromautoimpute.analysisimportMiLinearRegression# By default, use statsmodels OLS and MultipleImputer()simple_lm=MiLinearRegression()# fit the model on each multiply imputed dataset and pool parameterssimple_lm.fit(X_train,y_train)# get summary of fit, which includes pooled parameters under Rubin's rules# also provides diagnostics related to analysis after multiple imputationsimple_lm.summary()# make predictions on a new dataset using pooled parameterspredictions=simple_lm.predict(X_test)# Control both the regression used and the MultipleImputer itselfmultiple_imputer_arguments=dict(n=3,strategy={"salary":"pmm","gender":"bayesian binary logistic","age":"norm"},predictors={"salary":"all","gender":["salary","education","weight"]},imp_kwgs={"pmm":{"fill_value":"random"}},visit="left-to-right")complex_lm=MiLinearRegression(model_lib="sklearn",# use sklearn linear regressionmi_kwgs=multiple_imputer_arguments# control the multiple imputer)# fit the model on each multiply imputed datasetcomplex_lm.fit(X_train,y_train)# get summary of fit, which includes pooled parameters under Rubin's rules# also provides diagnostics related to analysis after multiple imputationcomplex_lm.summary()# make predictions on new dataset using pooled parameterspredictions=complex_lm.predict(X_test)

请注意,我们还可以将预先指定的多处理器传递给任一分析模型,而不是使用mi-kwgs。这是我们的选择,这是一个优先的问题。如果我们传递一个预先指定的multipleimputer,则忽略mi-kwgs中的任何内容,尽管mi-kwgs参数仍然有效。

fromautoimpute.imputationsimportMultipleImputerfromautoimpute.analysisimportMiLinearRegression# create a multiple imputer firstcustom_imputer=MultipleImputer(n=3,strategy="pmm",return_list=True)# pass the imputer to a linear regression modelcomplex_lm=MiLinearRegression(mi=custom_imputer,model_lib="statsmodels")# proceed the same as the previous examplescomplex_lm.fit(X_train,y_train).predict(X_test)complex_lm.summary()

为了更深入地了解该软件包可以正常工作并提供其可用功能,请参见我们的教程网站

版本和依赖项

  • 巨蟒3.6+
  • 依赖项:
    • numpy>;=1.15.4
    • scipy>;=1.2.1
    • 熊猫>;=0.20.3
    • statsmodels>;=0.9.0
    • scikit learn>;=0.20.2
    • xgboost>;=0.83
    • pymc3>;=3.5
    • seaborn>;=0.9.0
    • 缺失no>;=0.4.1

Windows用户的注意事项

  • autoimpute可以在windows上工作,但是用户可能会对pymc3的贝叶斯方法有困难。(请参阅"话语")
  • 当使用多个链进行采样时,用户可能会收到运行时错误'无法pickle fortran对象'
  • 要克服这个错误,有两件事要做:
    • 重新安装ano和pymc3。确保删除主文件夹中的"无缓存"。
    • 在此过程中升级joblib,它负责生成错误(pymc3在引擎盖下使用joblib)。
    • pm.sample中设置cores=1。这应该是最后的办法,因为这意味着后验取样将只使用1个岩芯。不使用多处理将大大降低贝叶斯插补方法的速度。
  • 如果您在windows上成功解决了这个问题并有更好的解决方案,请联系我们!

创建者和维护者

约瑟夫·卡尼–@kearnz
沙希德·巴克特-@shabarka
请参见作者页以获得联系!

许可证

根据麻省理工学院的许可证发行。有关详细信息,请参见许可证

贡献

为我们的项目做出贡献的准则。有关详细信息,请参见贡献

贡献者行为准则

改编自贡献者契约,1.0.0版。有关更多信息,请参见行为准则。

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

推荐PyPI第三方库


热门话题
JavaSpringbean已创建但未自动连接   java LibGDX游戏在三星Galaxy Grand Prime上结束   如何在Java中列出字符串句子中所有匹配条件的单词   java在Recyclerview中使用“putExtra”传递数据   java从一个特定的数组中提取特定的JSON对象,以便在Android中通过一个意图放入另一个活动   java需要使用IntelliJ和设置项目SDK的帮助   java springcontextindexer和Swagger 3   java使用indexOf和substring计算数字   java使用xml解析在word文档中查找隐式分页符   在添加<context:componentscan basepackage=“com.young.user”/   java无条件更改JTable单元格的背景色   选择列表中的java调用oracle函数:节点无数据类型   java如何添加缓冲图像作为JFrame的背景,然后在此图像上添加面板?   java Javadoc找不到用scala编写的类   java连接到文件共享程序的IP地址   java将数组元素加载到集合中   Tomcat中的java servlet、过滤器和线程   非Bean对象中的java EJB CDI注入?   java与println和printf的不同舍入