2
$\begingroup$

I am trying to validate my processes in terms of how I am engaging in model stacking for binary classification. Say I have two models as my base models, models A and B both with different classifiers and model C as my meta model.

My steps are as below.

  1. Split data into train, test sets
  2. Split my test set into a validation set (for my meta model training), and a final testing set.
  3. Train my base models A and B, on the training set using CV. Return the test statistics on the base models on my final testing set.
  4. Train my meta model using the probabilities generated in the base models on the validation set in part 2. Return the test statistics on the meta model on the final testing set.
  5. Compare the testing results from models A,B,C.
$\endgroup$
1
  • 1
    $\begingroup$ Good work. This seems mostly OK, just I think you are restricting the training set of model C a bit too aggressively. Please see my answer below for more details. $\endgroup$
    – usεr11852
    Commented Nov 13 at 3:32

1 Answer 1

1
$\begingroup$

These steps appear reasonably coherent for setting up a model stacking workflow for binary classification. Two minor points and a medium one:

  1. It is unclear if feature engineering is done for the metamodel C, that could be beneficial.
  2. The metamodel C could also be trained using cross-validation.
  3. The base models A and B are trained using CV on the training set (which is correct), but when generating predictions for metamodel C, we only need to ensure these predictions are out-of-fold predictions. I think in the quest to avoid data leakage, we are using an unnecessarily small training set for the metamodel.

The two most straightforward reference on stacking I have seen are:

  1. Machine Learning Design Patterns by Lakshmanan et al. (Nice but not too in-depth)
  2. The Kaggle Book by Banachewicz & Massaron. (Quite nice - see for example the Diagram of a two-layer stacking process with final averaging of predictions)

Both books cover considerations around stacking in reasonable detail and even provide code examples. Use those before getting your own variants. The sklearn documentation example on: Combine predictors using stacking is very good too.

$\endgroup$
6
  • $\begingroup$ Thanks for the information. I have a couple of questions, relative to your points 1. Does it make sense to retain features used during base model training for our meta model? 3. How can I remedy the small training set for the metamodel? Should I do a larger % split in my initial train_test split? $\endgroup$
    – user54565
    Commented Nov 13 at 6:03
  • $\begingroup$ One way I thought to remedy point 3, was to replace a traditional 80-20% (training-test split) with a large proportion to the testing set, say a 60%-40% split. Then within the testing split, I would do a more traditional 80-20% split (meta model training set -final testing set). $\endgroup$
    – user54565
    Commented Nov 13 at 6:49
  • $\begingroup$ I am happy I could help. 1. Yes, it might be helpful. Ultimately, if we do "some fit" we can always regularise appropriately. 2. No, we can be using the OoF prediction from the first step CV directly (see The Kaggle Book on this). 3. The initial train/test split seems fine as it is. $\endgroup$
    – usεr11852
    Commented Nov 13 at 11:24
  • $\begingroup$ In regards of using the OoF predictions from the first step CV, would it be considered data leakage if I did hyper parameter tuning on the base models using all of the training data before engaging in finding OoF predictions? This way I would know the best hyper parameters in my base models so that I would generate better base model predictions/features, for the meta model. $\endgroup$
    – user54565
    Commented Nov 13 at 20:36
  • 1
    $\begingroup$ I think not, you are not reusing the same data twice among the meta and the base models. Do you? $\endgroup$
    – usεr11852
    Commented Nov 13 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.