org.apache.ignite.ml.tree.randomforest

## Class RandomForestTrainer<L,S extends ImpurityComputer<BootstrappedVector,S>,T extends RandomForestTrainer<L,S,T>>

- java.lang.Object
- - org.apache.ignite.ml.trainers.DatasetTrainer<M,Double>
  - - org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer<ModelsComposition>
    - - org.apache.ignite.ml.tree.randomforest.RandomForestTrainer<L,S,T>

- Type Parameters:
    `L` - Type of statistics aggregator for leaf values computing.
    `S` - Type of impurity computer specific for algorithm.
    `T` - Type of child of RandomForestTrainer using in with-methods.
  Direct Known Subclasses:
    RandomForestClassifierTrainer, RandomForestRegressionTrainer

      public abstract class RandomForestTrainer<L,S extends ImpurityComputer<BootstrappedVector,S>,T extends RandomForestTrainer<L,S,T>>
      extends SingleLabelDatasetTrainer<ModelsComposition>

  Class represents a realization of Random Forest algorithm. Main idea of this realization is that at each learning iteration it tries to aggregate statistics on impurity for each corner nodes (leaves that may be splitted on a new iteration) in each trees in random forest. It requires one map-reduce operation over learning dataset. After such aggregation the algorithm selects split points for each corner nodes of create leaf nodes. The algorithm stops when there is no splitting for nodes in trees. At last stage the algorithm aggregates statistics on labels for leaf nodes in one map-reduce step and sets values to leafs based these statistics.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.ignite.ml.trainers.DatasetTrainer

      `DatasetTrainer.EmptyDatasetException`

  - ### Field Summary

    - ### Fields inherited from class org.apache.ignite.ml.trainers.DatasetTrainer

      `envBuilder, environment`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RandomForestTrainer(List<FeatureMeta> meta)` Create an instance of RandomForestTrainer.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract ModelsComposition` | `buildComposition(List<TreeRoot> models)` Returns composition of built trees.
    `protected abstract ImpurityHistogramsComputer<S>` | `createImpurityHistogramsComputer()` Creates an instance of Histograms Computer corresponding to RF implementation.
    `protected abstract LeafValuesComputer<L>` | `createLeafStatisticsAggregator()` Creates an instance of Leaf Statistics Aggregator corresponding to RF implementation.
    `<K,V> ModelsComposition` | `fitWithInitializedDeployingContext(DatasetBuilder<K,V> datasetBuilder, Preprocessor<K,V> preprocessor)` Trains model based on the specified data.
    `protected boolean` | `init(Dataset<EmptyContext,BootstrappedDatasetPartition> dataset)` Init-step before learning.
    `protected ArrayList<TreeRoot>` | `initTrees(Queue<TreeNode> treesQueue)` Creates list of trees.
    `protected abstract T` | `instance()`
    `boolean` | `isUpdateable(ModelsComposition mdl)`
    `protected <K,V> ModelsComposition` | `updateModel(ModelsComposition mdl, DatasetBuilder<K,V> datasetBuilder, Preprocessor<K,V> preprocessor)` Gets state of model in arguments, update in according to new data and return new model.
    `T` | `withAmountOfTrees(int amountOfTrees)`
    `T` | `withFeaturesCountSelectionStrgy(Function<List<FeatureMeta>,Integer> strgy)`
    `T` | `withMaxDepth(int maxDepth)`
    `T` | `withMinImpurityDelta(double minImpurityDelta)`
    `T` | `withNodesToLearnSelectionStrgy(Function<Queue<TreeNode>,List<TreeNode>> strgy)` Sets strategy for selection nodes from learning queue in each iteration.
    `T` | `withSeed(long seed)`
    `T` | `withSubSampleSize(double subSampleSize)`

    - ### Methods inherited from class org.apache.ignite.ml.trainers.DatasetTrainer

      `fit, fit, fit, fit, fit, fit, getLastTrainedModelOrThrowEmptyDatasetException, identityTrainer, learningEnvironment, update, update, update, update, update, withConvertedLabels, withEnvironmentBuilder`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RandomForestTrainer

          public RandomForestTrainer(List<FeatureMeta> meta)

      Create an instance of RandomForestTrainer.
      Parameters:
        `meta` - Features Meta.

  - ### Method Detail

    - #### fitWithInitializedDeployingContext

          public <K,V> ModelsComposition fitWithInitializedDeployingContext(DatasetBuilder<K,V> datasetBuilder,
                                                                            Preprocessor<K,V> preprocessor)

      Trains model based on the specified data.
      Specified by:
        `fitWithInitializedDeployingContext` in class `DatasetTrainer<ModelsComposition,Double>`
      Type Parameters:
        `K` - Type of a key in `upstream` data.
        `V` - Type of a value in `upstream` data.
      Parameters:
        `datasetBuilder` - Dataset builder.
        `preprocessor` - Extractor of `UpstreamEntry` into `LabeledVector`.
      Returns:
        Model.

    - #### instance

          protected abstract T instance()

      Returns:
        an instance of current object with valid type in according to inheritance.

    - #### withAmountOfTrees

          public T withAmountOfTrees(int amountOfTrees)

      Parameters:
        `amountOfTrees` - Count of trees.
      Returns:
        an instance of current object with valid type in according to inheritance.

    - #### withSubSampleSize

          public T withSubSampleSize(double subSampleSize)

      Parameters:
        `subSampleSize` - Subsample size.
      Returns:
        an instance of current object with valid type in according to inheritance.

    - #### withMaxDepth

          public T withMaxDepth(int maxDepth)

      Parameters:
        `maxDepth` - Max depth.
      Returns:
        an instance of current object with valid type in according to inheritance.

    - #### withMinImpurityDelta

          public T withMinImpurityDelta(double minImpurityDelta)

      Parameters:
        `minImpurityDelta` - Min impurity delta.
      Returns:
        an instance of current object with valid type in according to inheritance.

    - #### withFeaturesCountSelectionStrgy

          public T withFeaturesCountSelectionStrgy(Function<List<FeatureMeta>,Integer> strgy)

      Parameters:
        `strgy` - Strgy.
      Returns:
        an instance of current object with valid type in according to inheritance.

    - #### withNodesToLearnSelectionStrgy

          public T withNodesToLearnSelectionStrgy(Function<Queue<TreeNode>,List<TreeNode>> strgy)

      Sets strategy for selection nodes from learning queue in each iteration.
      Parameters:
        `strgy` - Strgy.

    - #### withSeed

          public T withSeed(long seed)

      Parameters:
        `seed` - Seed.
      Returns:
        an instance of current object with valid type in according to inheritance.

    - #### init

          protected boolean init(Dataset<EmptyContext,BootstrappedDatasetPartition> dataset)

      Init-step before learning. It may be useful collecting labels statistics step for classification.
      Parameters:
        `dataset` - Dataset.

    - #### isUpdateable

          public boolean isUpdateable(ModelsComposition mdl)

      Specified by:
        `isUpdateable` in class `DatasetTrainer<ModelsComposition,Double>`
      Parameters:
        `mdl` - Model.
      Returns:
        True if current critical for training parameters correspond to parameters from last training.

    - #### updateModel

          protected <K,V> ModelsComposition updateModel(ModelsComposition mdl,
                                                        DatasetBuilder<K,V> datasetBuilder,
                                                        Preprocessor<K,V> preprocessor)

      Gets state of model in arguments, update in according to new data and return new model.
      Specified by:
        `updateModel` in class `DatasetTrainer<ModelsComposition,Double>`
      Type Parameters:
        `K` - Type of a key in `upstream` data.
        `V` - Type of a value in `upstream` data.
      Parameters:
        `mdl` - Learned model.
        `datasetBuilder` - Dataset builder.
        `preprocessor` - Extractor of `UpstreamEntry` into `LabeledVector`.
      Returns:
        Updated model.

    - #### createImpurityHistogramsComputer

          protected abstract ImpurityHistogramsComputer<S> createImpurityHistogramsComputer()

      Creates an instance of Histograms Computer corresponding to RF implementation.

    - #### createLeafStatisticsAggregator

          protected abstract LeafValuesComputer<L> createLeafStatisticsAggregator()

      Creates an instance of Leaf Statistics Aggregator corresponding to RF implementation.

    - #### initTrees

          protected ArrayList<TreeRoot> initTrees(Queue<TreeNode> treesQueue)

      Creates list of trees.
      Parameters:
        `treesQueue` - Trees queue.
      Returns:
        List of trees.

    - #### buildComposition

          protected abstract ModelsComposition buildComposition(List<TreeRoot> models)

      Returns composition of built trees.
      Parameters:
        `models` - Models.
      Returns:
        composition of built trees.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.0
Release Date | : October 15 2020