Package: hyperimpute
HyperImpute - A library for NaNs and nulls.HyperImpute simplifies the selection process of a data imputation algorithm for your ML pipelines.
It includes various novel algorithms for missing data and is compatible withsklearn.HyperImpute features:rocket: Fast and extensible dataset imputation algorithms, compatible with sklearn.:key: New iterative imputation method: HyperImpute.:cyclone: Classic methods: MICE, MissForest, GAIN, MIRACLE, MIWAE, Sinkhorn, SoftImpute, etc.:fire: Pluginable architecture.:rocket: InstallationThe library can be installed from PyPI using$pipinstallhyperimputeor from source, using$pipinstall.:boom: Sample UsageList available imputersfromhyperimpute.plugins.imputersimportImputersimputers=Imputers()imputers.list()Impute a dataset using one of the available methodsimportpandasaspdimportnumpyasnpfromhyperimpute.plugins.imputersimportImputersX=pd.DataFrame([[1,1,1,1],[4,5,np.nan,np.nan],[3,3,9,9],[2,2,2,2]])method="gain"plugin=Imputers().get(method)out=plugin.fit_transform(X.copy())print(method,out)Specify the baseline models for HyperImputeimportpandasaspdimportnumpyasnpfromhyperimpute.plugins.imputersimportImputersX=pd.DataFrame([[1,1,1,1],[4,5,np.nan,np.nan],[3,3,9,9],[2,2,2,2]])plugin=Imputers().get("hyperimpute",optimizer="hyperband",classifier_seed=["logistic_regression"],regression_seed=["linear_regression"],)out=plugin.fit_transform(X.copy())print(out)Use an imputer with a SKLearn pipelineimportpandasaspdimportnumpyasnpfromsklearn.pipelineimportPipelinefromsklearn.ensembleimportRandomForestRegressorfromhyperimpute.plugins.imputersimportImputersX=pd.DataFrame([[1,1,1,1],[4,5,np.nan,np.nan],[3,3,9,9],[2,2,2,2]])y=pd.Series([1,2,1,2])imputer=Imputers().get("hyperimpute")estimator=Pipeline([("imputer",imputer),("forest",RandomForestRegressor(random_state=0,n_estimators=100)),])estimator.fit(X,y)Write a new imputation pluginfromsklearn.imputeimportKNNImputerfromhyperimpute.plugins.imputersimportImputers,ImputerPluginimputers=Imputers()knn_imputer="custom_knn"classKNN(ImputerPlugin):def__init__(self)->None:super().__init__()self._model=KNNImputer(n_neighbors=2,weights="uniform")@staticmethoddefname():returnknn_imputer@staticmethoddefhyperparameter_space():return[]def_fit(self,*args,**kwargs):self._model.fit(*args,**kwargs)returnselfdef_transform(self,*args,**kwargs):returnself._model.transform(*args,**kwargs)imputers.add(knn_imputer,KNN)assertimputers.get(knn_imputer)isnotNoneBenchmark imputation models on a datasetfromsklearn.datasetsimportload_irisfromhyperimpute.plugins.imputersimportImputersfromhyperimpute.utils.benchmarksimportcompare_modelsX,y=load_iris(as_frame=True,return_X_y=True)imputer=Imputers().get("hyperimpute")compare_models(name="example",evaluated_model=imputer,X_raw=X,ref_methods=["ice","missforest"],scenarios=["MAR"],miss_pct=[0.1,0.3],n_iter=2,)📓 TutorialsTutorial 0: Imputation basicsTutorial 1: AutoML for imputationTutorial 2: Benchmark:zap: Imputation methodsThe following table contains the default imputation plugins:StrategyDescriptionCodeHyperImputeIterative imputer using both regression and classification methods based on linear models, trees, XGBoost, CatBoost and neural netsplugin_hyperimpute.pyMeanReplace the missing values using the mean along each column withSimpleImputerplugin_mean.pyMedianReplace the missing values using the median along each column withSimpleImputerplugin_median.pyMost-frequentReplace the missing values using the most frequent value along each column withSimpleImputerplugin_most_freq.pyMissForestIterative imputation method based on Random Forests usingIterativeImputerandExtraTreesRegressorplugin_missforest.pyICEIterative imputation method based on regularized linear regression usingIterativeImputerandBayesianRidgeplugin_ice.pyMICEMultiple imputations based on ICE usingIterativeImputerandBayesianRidgeplugin_mice.pySoftImputeLow-rank matrix approximation via nuclear-norm regularizationplugin_softimpute.pyEMIterative procedure which uses other variables to impute a value (Expectation), then checks whether that is the value most likely (Maximization) -EM imputation algorithmplugin_em.pySinkhornMissing Data Imputation using Optimal Transportplugin_sinkhorn.pyGAINGAIN: Missing Data Imputation using Generative Adversarial Netsplugin_gain.pyMIRACLEMIRACLE: Causally-Aware Imputation via Learning Missing Data Mechanismsplugin_miracle.pyMIWAEMIWAE: Deep Generative Modelling and Imputation of Incomplete Dataplugin_miwae.py:hammer: TestsInstall the testing dependencies usingpipinstall.[testing]The tests can be executed usingpytest-vsxCitingIf you use this code, please cite the associated paper:@article{Jarrett2022HyperImpute,
  doi = {10.48550/ARXIV.2206.07769},
  url = {https://arxiv.org/abs/2206.07769},
  author = {Jarrett, Daniel and Cebere, Bogdan and Liu, Tennison and Curth, Alicia and van der Schaar, Mihaela},
  keywords = {Machine Learning (stat.ML), Machine Learning (cs.LG), FOS: Computer and information sciences, FOS: Computer and information sciences},
  title = {HyperImpute: Generalized Iterative Imputation with Automatic Model Selection},
  year = {2022},
  booktitle={39th International Conference on Machine Learning},
}