There are various techniques to build counterfactual estimations of certain variables for linear models in observational studies.
Some of those are based on comparing the change in the predicted outcome when varying the exposure variable of interest on the whole dataset, keeping the other variables fixed (conditional effect).
Would this technique be valid also for non-linear machine learning models? Given a $$\hat{f} = E(f(x, C))$$ that is a non-linear function of the exposure x and covariates C that estimate the real data-generating process $$y = f(x, C)$$ would $$\Delta\hat{y} = \hat{y}_1 - \hat{y}_0 = \hat{f}(1, C) - \hat{f}(0, C)$$
be a good estimator of $$\Delta y = y_1 - y_0 = f(1, C) - f(0, C)$$ with $\hat{y}_1, \hat{y}_0, y_1, y_0$ being the predicted and real conterfactual outcome if the exposure was present or not?
(sorry if the notation was incorrect, feel free to edit)