CART handles a missing split variable at prediction time with surrogate splits: backup splits on other features that best mimic the partition made by the primary split. Missing values are np.nan.
Implement find_surrogates(X, feature, threshold, n_surrogates):
x[feature] <= threshold. Only rows where the primary feature is observed define the target partition."same" (left if x[f] <= t) and "reverse" (left if x[f] > t). The agreement of a candidate is the fraction of those rows sent to the same side as the primary split. Keep each feature's best candidate (first found on ties: lower threshold first, "same" before "reverse"). Skip features with fewer than 2 distinct values.n_surrogates tuples (feature, threshold, direction, agreement), sorted by agreement (highest first, lower feature index on ties), with Python int, float, str, float values.Implement route(x, node) for a single row x, where node is a dict with keys "feature", "threshold", "surrogates" (a list as returned above) and "majority" ("left" or "right"). Return "left" or "right" using the primary split if its feature is observed, otherwise the first surrogate whose feature is observed, otherwise the majority side.