I am not sure if you are familiar with this topic. If not, read Ensemble learning on Wikipedia.
Now, to your question. First boosting. Here, you use a meta-algorithm to improve an (one) algorithm. It usually does a good job, but sometimes it over-fits, meaning that It appears to be better, but it actually isn't. For your problem - yes, you can use boosting on each of the used algorithms.
As for stacking - here, you run all of the algorithms at once, and then make a decision which of them you will use for the final decision (somewhat similar to voting). You usually make this decision with logistic regression (in your case, you will have two different instances of logistic regression as you already use one for solving your problem).
If you want to use both boosting and stacking, you first have to boost each and every one of your algorithms, and then use another algorithm (e.g. logistic regression) to stack them into an ensemble.
Question 1: local prediction & cross validation
Looking for closeby cases and upweighting them for prediction is referred to as local models or local prediction.
For the proper way to do cross validation, remember that for each fold, you only use training cases, and then do with the test cases exactly what you do for prediciton of a new unkown case.
I'd recommend to see the calculation of $X_1$ as part of the prediction. E.g. in a two level model consisting of a $n$ nearest neighbours + a second level model:
- For each of the training cases, find the $n$ nearest neighbours and calculate $X_{11}$
- Calculate the "2nd level" model based on $X_1, ..., X_{11}$.
So for prediction of a case $X_{new}$, you
- find the $n$ nearest neighbours and calculate the $X_{11}$ for the new case
- then calculate the prediction of the 2nd level model.
You use exactly this prediction procedure to predict the test cases in the cross validation.
Question 2: combining predictions
random forest tends to overfit on training data set
Usually random forest will overfit only in situations where you have a hierarchical/clustered data structer that creates a dependence between (some) rows of your data.
Boosting is more prone to overfitting because of the iteratively weighted average (as opposed to the simple average of the random forest).
I did not yet completely understand your question (see comment).
But here's my guess:
I assume you want to find out the optimal weight you should use for random forest and boosted prediction, which is a linear model of those two models.
(I don't see how you could use the individual trees within those ensemble models because the trees will totally change between the splits). This again amounts to a 2 level model (or 3 levels if combined with the approach of question 1).
The general answer here is that whenever you do a data-driven model or hyperparameter optimization (e.g. optimize the weights for random forest prediction and gradient boosted prediction by test/cross validation results), you need to do an independent validation to assess the real performance of the resulting model. Thus you need either yet another independent test set, or a so-called nested or double cross validation.
- So the 1st approach would not work unless you derive the weights from the training data.
- As you point out for the 2nd approach, having more and more levels of cross validation needs huge sample sizes to start with.
I'd recommend a different approach here: try to cut down as far as possible the number of splits you need by doing as few data-driven hyperparameter calculations or optimizations as possible. There cannot be any discussion about the need of a validation of the final model. But you may be able to show that no inner splitting is needed if you can show that the models you try to stack are not overfit. In addition this would remove the need to stack at all:
Ensemble models only help if the underlying individual models suffer from variance, i.e. are unstable. (Or if they are biased in opposing directions, so the ensembe would roughly cancel the individual biases. I suspect that this is not the case here, assuming that your GBM uses trees like the RF.)
As for the instability, you can measure this easily by repeated aka iterated cross validation (see e.g. this answer). If this does not point to substantial variance in the prediction of the same case by models built on slightly varying training data (i.e. if your RF and GBM are stable), producing an ensemble of the ensemble models is not going to help.
Best Answer
Stacking ensembles are usually heterogeneous ensembles that use learners of different types. In order for ensemble methods to be more accurate than any of its individual members the base learners have to be as accurate as possible and as diverse as possible. Diversity can be achieved by using different learners, sub-sampling the data and/or the features, or using learners with different parameter settings. It is possible that one of the base learners is a random forest in which case there will be sub-sampling of data and features. A potential danger in using a sub-set of features for each base model is that the accuracy will degrade in favor of greater diversity. This may be dataset specific and may or may not improve the accuracy of the overall ensemble. It seems that cross-validation will give an experimental answer to this question.