Generalized weighting for bagged ensembles