Absent categorical data levels in Bootstrap samples I have a huge dataset ($n$ around five million, $p$ around three thousand) for a classification problem, where my interest is predictive class probabilities for test data, not the target. I shall be using bootstrap samples to estimate the smoothed probabilities from various models.
The problem is when I bootstrap the cases not all the levels in the categorical predictors will be in every resample. Given that I need parameters for all levels when working with the test set, I'm unsure of what to do.
I read Agresti's Categorical Data Analysis, but there doesn't seem to be mention of this.
I have thought of 2 possibilities:


*

*Insert a base composition of varied cases in every resample so that all levels are included for all predictors.

*Define all levels for each categorical variable with reference to the data schema and run the models.
I'm having to think about this because my resamples are pulled as CSV data from a SQL database and I would usually use read.csv() which automagically handles levels, preference relations and levels for categorical data using the cases in the CSV file. (Pulling all of the data in one csv is not an option due to resource constraints.)
 A: Stratified bootstrap sampling is perfectly permissible to use.  If you have the proportions of the class levels in the population I think you just make the class level a stratum and sample cases with each strata proportional to their representation in the population.  Stratified bootstrap sampling amounts to sampling with replacement a specified number of times in each stratum.
Edit to the original answer: One aspect of the problem that was not addressed originally when the question was asked was a sensible way of reducing the number of predictors. The value of stratification is to reduce the overall variation.  With so many predictors some may not be very useful anyway and hence the number of levels could possibly be reduced without hurting the value of the predictors for classification seriously. To emphasize what I said in the original answer since the bootstrap samples with replacement from each individual stratum no strata will be left out in any bootstrap sample. I think this addresses the recent comment by @kjetilbHalvorsen.
