Missing values and monotonicity
Quick answer
Boosting libraries can route missing numerical features through learned or configured paths rather than requiring every value to be imputed. Monotonic constraints restrict how a prediction changes as one numeric feature increases while the other features stay fixed. These are modeling assumptions, not proof of causal relationships. Static examples tested locally with Python 3.13.5, XGBoost 3.1.3, LightGBM 4.6.0 and CatBoost 1.2.8 where imported. ByteMind package execution is unverified.
Audit adjacent predictions
p=[1,2,2,1,4]print([i for i in range(len(p)-1) if p[i+1]<p[i]])Observed local output:
[2]The change from index 2 to 3 violates a nondecreasing constraint; the flat pair does not.
How it works
A missing sensor reading may contain information about collection failures. Preserve the difference between a true zero and a missing value. XGBoost tree learning can choose a default split direction for missing observations. LightGBM handles NaN by default; zero_as_missing changes the interpretation of zeros, including implicit sparse zeros. CatBoost numerical nan_mode may use Min or Max treatment, or forbid missing values; categorical missing labels need their own string policy. Check each framework’s input schema and test a missing-value row. A positive monotonic constraint means f(x_a,z) <= f(x_b,z) whenever x_a <= x_b and z is fixed; a negative constraint reverses the inequality. A flat interval is allowed. Do not compare rows in which other features also changed. XGBoost monotone_constraints=(1,0) and LightGBM monotone_constraints=[1,0] apply to two numeric features; CatBoost monotone_constraints=[1,0] is a CPU lane in this lesson. Not every tree method, objective, device or categorical combination supports the same constraints. Use held-out validation to measure the cost of the restriction. Checking finitely many pairs catches some errors but cannot independently prove global monotonicity. Missing values are not ordered real numbers, so keep their behavior out of the ordered finite-value audit.
Check native missing values and monotonicity
import numpy as npimport pandas as pdfrom xgboost import XGBRegressorfrom lightgbm import LGBMRegressorfrom catboost import CatBoostRegressorX=pd.DataFrame({"load":[0,1,2,3,4,5,np.nan,2]*4,"shift":[0]*32})y=[0,3,2,6,5,9,4,3]*4grid=pd.DataFrame({"load":[0,1,2,3,4,5,np.nan],"shift":[0]*7})models=[XGBRegressor(n_estimators=8,max_depth=2,n_jobs=1,device="cpu",tree_method="hist",monotone_constraints=(1,0),random_state=7),LGBMRegressor(n_estimators=8,num_leaves=4,min_child_samples=1,verbosity=-1,n_jobs=1,monotone_constraints=[1,0],random_state=7),CatBoostRegressor(iterations=8,depth=2,thread_count=1,task_type="CPU",monotone_constraints=[1,0],random_seed=7,verbose=False,allow_writing_files=False)]for m in models: p=m.fit(X,y).predict(grid) print(bool(np.all(np.diff(p[:-1])>=-1e-6)),bool(np.isfinite(p[-1])))Observed local output:
True TrueTrue TrueTrue TrueAll three CPU models pass the finite-grid check and produce a finite missing-row prediction. This does not certify every possible input.
Common mistakes
Do not fill every NaN with zero, constrain arbitrary integer codes as if ordered, or treat monotonic association as causal evidence. Do not infer a global guarantee from a handful of sampled pairs. GPU behavior is not verified here.
Practice and next steps
Add another fixed value of the second feature to the audit grid. Check consecutive predictions using a documented floating tolerance. Compare missing-value predictions separately, without ordering NaN against real values. Complete the knowledge check and staged exercise. Next: Fair CPU benchmark protocol.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Missing values and monotonicity — knowledge check
Apply missing values and monotonicity to new scenarios.
What must stay fixed when checking one monotone feature?
Is a flat prediction interval allowed?
What can zero_as_missing alter?
What does a finite grid audit establish?
How should numerical NaN be audited?