apache-ignite
55 строк · 2.3 Кб
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15= Bagging
16
17Bagging stands for bootstrap aggregation. One way to reduce the variance of an estimate is to average together multiple estimates. For example, we can train M different trees on different subsets of the data (chosen randomly with replacement) and compute the ensemble:
18
19image::images/bagging.png[]
20
21Bagging uses bootstrap sampling to obtain the data subsets for training the base learners. For aggregating the outputs of base learners, bagging uses voting for classification and averaging for regression.
22
23
24[source, java]
25----
26// Define the weak classifier.
27DecisionTreeClassificationTrainer trainer = new DecisionTreeClassificationTrainer(5, 0);
28
29// Set up the bagging process.
30BaggedTrainer<Double> baggedTrainer = TrainerTransformers.makeBagged(
31trainer, // Trainer for making bagged
3210, // Size of ensemble
330.6, // Subsample ratio to whole dataset
344, // Feature vector dimensionality
353, // Feature subspace dimensionality
36new OnMajorityPredictionsAggregator())
37.withEnvironmentBuilder(LearningEnvironmentBuilder
38.defaultBuilder()
39.withRNGSeed(1)
40);
41
42// Train the Bagged Model.
43BaggedModel mdl = baggedTrainer.fit(
44ignite,
45dataCache,
46vectorizer
47);
48----
49
50
51TIP: A commonly used class of ensemble algorithms are forests of randomized trees.
52
53== Example
54
55The full example could be found as a part of the Titanic tutorial https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_10_Bagging.java[here].
56
57