liveBook · Manning

Missing completely at random

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

Missing completely at random describes a missingness mechanism in which missingness is unrelated to observed or unobserved data.

Missing completely at random (MCAR) describes a missingness mechanism in which missingness is unrelated to both observed and unobserved variables. Missing values therefore occur randomly across the dataset, rather than reflecting a feature value or a hidden process. section 6.1.1

Start by investigating why values are missing before choosing a model strategy. Under MCAR, expected-value imputation can work well, while multivariate imputation can use correlations among predictors to reconstruct missing values. Gradient-boosted decision trees can also handle MCAR effectively, although direct imputation may remain easier to inspect and control. section 6.1.1 section 6.1.2

Distinguish MCAR from related mechanisms before processing the data:

  • MCAR means missingness is unrelated to observed and unobserved variables. section 6.1.1
  • MAR means observed variables explain missingness, while unobserved values do not. section 6.1.1
  • MNAR means missingness follows a systematic relationship involving the missing value itself; specialized treatment may be required. section 6.1.1
  • Use missing indicators when missingness is not completely random, and investigate the cause rather than relying automatically on GBDT defaults. section 6.1.2 section 7.1.5

Randomly masking continuous features

A practical comparison creates a five-percent random mask over continuous features, fills one copy with SimpleImputer, and fills another with IterativeImputer using a RandomForestRegressor. Mean absolute error can then compare simple and multivariate reconstruction.

Listing 6.2 Multivariate imputation
from sklearn.experimental import (
    enable_iterative_imputer
)                                                             #1
from sklearn.impute import SimpleImputer, IterativeImputer
from sklearn.ensemble import RandomForestRegressor
 
Xm = data[continuous].copy()                                  #2
missing_percentage = 0.05
np.random.seed(0)
mask = np.random.rand(*Xm.shape) < missing_percentage         #3
Xm[mask] = np.nan
 
simple_imputer = SimpleImputer()
Xm_si = simple_imputer.fit_transform(Xm)                      #4
 
rf = RandomForestRegressor(random_state=0, n_jobs=-1)         #5
multivariate_imputer = IterativeImputer(
    estimator=rf,
    max_iter=1,
    tol=0.01
)                                                             #6
Xm_mi = multivariate_imputer.fit_transform(Xm)                #7
 
mae = pd.DataFrame(
    {
        "simple": np.mean(
            np.abs(data[continuous] - Xm_si), axis=0
        ),
        "multivariate": np.mean(
            np.abs(data[continuous] - Xm_mi), axis=0
        )
     },
     index = continuous
)                                                             #8
print(mae)

Run the supplied pandas and scikit-learn listing to compare simple and multivariate imputation on randomly masked continuous data. section 6.1.1

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Defines MCAR, contrasts MAR and MNAR, and discusses imputation and GBDT handling without developing specialized MNAR treatment.
Examples
Uses a five-percent random mask, SimpleImputer, IterativeImputer, random forests, and accommodation review fields as contrasting cases.
What it assumes
Assumes familiarity with tabular predictors and missing values while introducing MCAR, MAR, MNAR, and imputation choices.
What you can do after
Apply it via missingness investigation to classify mechanisms and choose imputation, indicators, or GBDT handling appropriately.
How it connects
Connects MCAR with MAR, MNAR, imputation, missing indicators, multivariate imputation, and gradient-boosted decision trees.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.