Htun Teza
No Burmese version of this page

Uncertainty-aware imputation is now a Python package

, Software release, 3 min read

The method from our paper Uncertainty Aware Approach for Multiple Imputation Using Conventional and Machine Learning Models is now a Python package. Romen Samuel Rodis Wabina, the first author, wrote and maintains it.

The problem

Our hospital cohorts had many missing laboratory values:

CohortPatientsMissing per variable
Chronic kidney disease (CKD)31,0434% to 49%
Hypertension, Ramathibodi (HT-RAMA)140,04716% to 53%
Hypertension, Khon Kaen (HT-KKU)108,94228% to 68%

MICE, the usual method, fills one variable at a time from earlier filled values. An early error therefore moves into every later step.

The method

We kept MICE and changed what each model trains on. An uncertainty function scores how much each patient’s imputed values vary across imputations. Each model then trains only on the patients the function selects.

flowchart LR
  A[Impute one<br>variable] --> B[Score each<br>patient]
  B --> C[Train on selected<br>patients]
  C -->|next variable| A
  C -->|stable| D[Pool 5<br>datasets]
FunctionSelects patients with
Uncertainty sampling (US)the lowest variance
Probability of improvement (PI)the highest chance to improve the current best value
Expected improvement (EI)the largest expected improvement

We tested each function with linear regression, decision tree, random forest and XGBoost. To get known true values, we removed values from complete CKD records in the real missing patterns, then imputed them again.

Figure 1. How we made test data: listwise deletion keeps the complete records, which are split by the real missing patterns, then values in each pattern are blanked with probability p. From Wabina et al., Journal of Big Data (2025), Fig. 1, CC BY 4.0.

Results

In CKD, every function lowered the error of linear regression:

%%{init: {"xyChart": {"width": 640, "height": 300}}}%%
xychart-beta
  title "CKD, linear regression: RMSE (lower is better)"
  x-axis ["Plain MICE", "US", "PI", "EI"]
  y-axis "RMSE" 0 --> 0.2
  bar [0.168, 0.146, 0.132, 0.115]

Linear regression was the best model in all three cohorts:

CohortBestRMSEMAE
CKDLinear regression + EI0.120.36
HT-RAMALinear regression + US0.248.15
HT-KKULinear regression + US0.9812.00

The functions also kept imputed distributions close to the observed data. XGBoost was the exception: it did not improve and needed long tuning.

Use it

pip install uncertainty-imputation
from uncertainty_imputation import UncertaintyImputer

imputer = UncertaintyImputer(model="linear", acquisition="ei")
X_imputed = imputer.fit_transform(X_missing)  # DataFrame or array
scores = imputer.uncertainty_  # score per imputed cell

The acquisition key is us, pi or ei. The package also makes MCAR, MAR or MNAR test data, so you can repeat our test design on your own data. It needs Python 3.9 or later.

PyPI · Source code · Paper