Let's say my dataset has features $X_1$, $X_2$, $X_3$ and predicted variable Y. Now doing some feature engineering I came up with a feature X4 that is a mean(Y) of samples similar to the one we're looking at.
Before coming up with feature $X_4$ I did regular 10-fold CV. What is the correct way of including $X_4$ in validation? Am I correct to assume that $X_4$ for test set in each fold should only be based on samples from this test set?
I was looking into "impact-coding" which looks similar to what I'm doing, but was unable to find good info on cross-validating it.