NaiveBayesTrainer (Apache OpenNLP Tools 1.9.5 API)
Date: 2026-06-18

opennlp.tools.ml.naivebayes

## Class NaiveBayesTrainer

- java.lang.Object
- - opennlp.tools.ml.AbstractTrainer
  - - opennlp.tools.ml.AbstractEventTrainer
    - - opennlp.tools.ml.naivebayes.NaiveBayesTrainer

- All Implemented Interfaces:
    EventTrainer

      public class NaiveBayesTrainer
      extends AbstractEventTrainer

  Trains models using the combination of EM algorithm and Naive Bayes classifier which is described in: Text Classification from Labeled and Unlabeled Documents using EM Nigam, McCallum, et al paper of 2000

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `NAIVE_BAYES_VALUE`

    - ### Fields inherited from class opennlp.tools.ml.AbstractEventTrainer

      `DATA_INDEXER_ONE_PASS_REAL_VALUE, DATA_INDEXER_ONE_PASS_VALUE, DATA_INDEXER_PARAM, DATA_INDEXER_TWO_PASS_VALUE`

    - ### Fields inherited from class opennlp.tools.ml.AbstractTrainer

      `ALGORITHM_PARAM, CUTOFF_DEFAULT, CUTOFF_PARAM, ITERATIONS_DEFAULT, ITERATIONS_PARAM, TRAINER_TYPE_PARAM, VERBOSE_DEFAULT, VERBOSE_PARAM`

    - ### Fields inherited from interface opennlp.tools.ml.EventTrainer

      `EVENT_VALUE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NaiveBayesTrainer()`
    `NaiveBayesTrainer(TrainingParameters parameters)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `AbstractModel` | `doTrain(DataIndexer indexer)`
    `boolean` | `isSortAndMerge()`
    `AbstractModel` | `trainModel(DataIndexer di)`

    - ### Methods inherited from class opennlp.tools.ml.AbstractEventTrainer

      `getDataIndexer, isValid, train, train, validate`

    - ### Methods inherited from class opennlp.tools.ml.AbstractTrainer

      `getAlgorithm, getCutoff, getIterations, init, init`

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

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

    - ### Methods inherited from interface opennlp.tools.ml.EventTrainer

      `init, init`

- - ### Field Detail

    - #### NAIVE_BAYES_VALUE

          public static final String NAIVE_BAYES_VALUE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### NaiveBayesTrainer

          public NaiveBayesTrainer()

    - #### NaiveBayesTrainer

          public NaiveBayesTrainer(TrainingParameters parameters)

  - ### Method Detail

    - #### isSortAndMerge

          public boolean isSortAndMerge()

      Specified by:
        `isSortAndMerge` in class `AbstractEventTrainer`

    - #### doTrain

          public AbstractModel doTrain(DataIndexer indexer)
                                throws IOException

      Specified by:
        `doTrain` in class `AbstractEventTrainer`
      Throws:
        `IOException`

    - #### trainModel

          public AbstractModel trainModel(DataIndexer di)

Copyright © 2026 The Apache Software Foundation. All rights reserved.