An implementation of Bootstrap Aggregating, as described by LEO BREIMAN in "Bagging Predictors". Bagging is an ensemble learner, it takes a weak learner and trains several to create a better over result. Bagging is particularly useful when the base classifier has some amount of predictive
| 29 | * @author Edward Raff |
| 30 | */ |
| 31 | public class Bagging implements Classifier, Regressor, Parameterized |
| 32 | { |
| 33 | |
| 34 | private static final long serialVersionUID = -6566453570170428838L; |
| 35 | private Classifier baseClassifier; |
| 36 | private Regressor baseRegressor; |
| 37 | private CategoricalData predicting; |
| 38 | private int extraSamples; |
| 39 | private int rounds; |
| 40 | private boolean simultaniousTraining; |
| 41 | private Random random; |
| 42 | private List learners; |
| 43 | |
| 44 | /** |
| 45 | * The number of rounds of bagging that will be used by default in the constructor: {@value #DEFAULT_ROUNDS} |
| 46 | */ |
| 47 | public static final int DEFAULT_ROUNDS = 20; |
| 48 | /** |
| 49 | * The number of extra samples to take when bagging in each round used by default in the constructor: {@value #DEFAULT_EXTRA_SAMPLES} |
| 50 | */ |
| 51 | public static final int DEFAULT_EXTRA_SAMPLES = 0; |
| 52 | /** |
| 53 | * The default behavior for parallel training, as specified by {@link #setSimultaniousTraining(boolean) } is {@value #DEFAULT_SIMULTANIOUS_TRAINING} |
| 54 | */ |
| 55 | public static final boolean DEFAULT_SIMULTANIOUS_TRAINING = true; |
| 56 | |
| 57 | /** |
| 58 | * Creates a new Bagger for classification. This can not be changed after construction. |
| 59 | * |
| 60 | * @param baseClassifier the base learner to use. |
| 61 | */ |
| 62 | public Bagging(Classifier baseClassifier) |
| 63 | { |
| 64 | this(baseClassifier, DEFAULT_EXTRA_SAMPLES, DEFAULT_SIMULTANIOUS_TRAINING); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates a new Bagger for classification. This can not be changed after construction. |
| 69 | * |
| 70 | * @param baseClassifier the base learner to use. |
| 71 | * @param extraSamples how many extra samples past the training size to take |
| 72 | * @param simultaniousTraining controls whether base learners are trained sequentially or simultaneously |
| 73 | */ |
| 74 | public Bagging(Classifier baseClassifier, int extraSamples, boolean simultaniousTraining) |
| 75 | { |
| 76 | this(baseClassifier, extraSamples, simultaniousTraining, DEFAULT_ROUNDS, new Random(1)); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Creates a new Bagger for classification. This can not be changed after construction. |
| 81 | * |
| 82 | * @param baseClassifier the base learner to use. |
| 83 | * @param extraSamples how many extra samples past the training size to take |
| 84 | * @param simultaniousTraining controls whether base learners are trained sequentially or simultaneously |
| 85 | * @param rounds how many rounds of bagging to perform. |
| 86 | * @param random the source of randomness for sampling |
| 87 | */ |
| 88 | public Bagging(Classifier baseClassifier, int extraSamples, boolean simultaniousTraining, int rounds, Random random) |
nothing calls this directly
no outgoing calls
no test coverage detected