python中的插补方法
autoimpute的Python项目详细描述
autoimpute
是一个用于分析和实现插补方法的python包!
查看我们的网站以了解更详细的自动输入。
查看我们的文档以获取《开发人员指南》自动输入
安装
自动输入
现在已注册到PYPI!使用pip install autoimpute下载
- 最新版本的自动输入是
0.11.4
- 如果
pip
缓存了旧版本,请尝试pip install--no cache dir--upgrade autoimpute
- 如果要使用开发分支,请使用以下脚本:
开发
大多数机器学习算法期望干净完整的数据集,但现实世界中的数据是混乱和缺失的。不幸的是,处理丢失的数据相当复杂,所以编程语言通常将此责任推给最终用户。默认情况下,r会删除所有缺少数据的记录,这种方法易于实现,但在实践中常常会出现问题。对于更丰富的插补策略,r有多个包来处理丢失的数据( 因此,该包通过提供更清晰的插补过程、使插补方法更易访问以及测量插补方法在监督回归和分类中的影响来帮助python用户。在这样做的过程中,这个包将丢失的数据插补方法带到python世界中,并使它们在python机器学习中很好地工作。g项目(特别是利用scikit learn的项目)。最后,这个包提供了自己的有监督机器学习方法的实现,这些方法将scikit learn和statsmodels扩展到多个输入数据集。 自动输入设计为用户友好和灵活。在执行插补时,自动插补直接适用于 现在,我们将使用两个 估算可以简单到: 或相当复杂,例如: autoimpute还将有监督的机器学习方法从 与输入法一样,自动输入法的分析方法可以简单也可以复杂: 请注意,我们还可以将预先指定的 为了更深入地了解该软件包可以正常工作并提供其可用功能,请参见我们的教程网站 Windows用户的注意事项: 约瑟夫·卡尼–@kearnz 根据麻省理工学院的许可证发行。有关详细信息,请参见许可证。 为我们的项目做出贡献的准则。有关详细信息,请参见贡献。 改编自贡献者契约,1.0.0版。有关更多信息,请参见行为准则。git clone -b dev --single-branch https://github.com/kearnz/autoimpute.git
cd autoimpute
python setup.py install
动机
MICE
,AMELIA
,tsimpute
,等等)。python用户并没有这么幸运。当最终用户在缺少记录的数据集上部署模型时,python的scikit learn会抛出一个运行时错误,并且几乎没有第三方包可以处理端到端的插补。主要功能
pandas
dataframes
支持的插补方法
<表><广告> < /广告><正文>单变量
多变量 时间序列/插值
平均值 线性回归
线性 中间值 二项logistic回归
二次型 模式 多项式logistic回归
立方 随机 随机回归
多项式 标准值 贝叶斯线性回归
样条曲线 分类
贝叶斯二元逻辑回归
时间加权 预测平均匹配 下一个OBS结转 局部剩余绘制 最后结转的OBS 待办事项
dask
dataframes示例用法
scikit learn
机器学习项目。输入源继承自sklearn的baseestimator
和transformerminxin
并实现fit
和transform
方法,使它们成为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)
scikit learn
和statsmodels
扩展到将它们应用于多个输入数据集(使用引擎盖下的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()
版本和依赖项
numpy
>;=1.15.4scipy
>;=1.2.1熊猫
>;=0.20.3statsmodels
>;=0.9.0scikit learn
>;=0.20.2xgboost
>;=0.83pymc3
>;=3.5seaborn
>;=0.9.0缺失no
>;=0.4.1'无法pickle fortran对象'
。pm.sample
中设置cores=1
。这应该是最后的办法,因为这意味着后验取样将只使用1个岩芯。不使用多处理将大大降低贝叶斯插补方法的速度。创建者和维护者
沙希德·巴克特-@shabarka
请参见作者页以获得联系!许可证
贡献
贡献者行为准则
推荐PyPI第三方库