Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-16840

Please save the aggregate term frequencies as part of the NaiveBayesModel

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Incomplete
    • 1.6.2, 2.0.0
    • None
    • ML

    Description

      I would like to visualize the structure of the NaiveBayes model in order to get additional insight into the patterns in the data. In order to do that I need the frequencies for each feature value per label.

      This exact information is computed in the NaiveBayes.run method (see "aggregated" variable), but then discarded when creating the model. Pi and theta are computed based on the aggregated frequency counts, but surprisingly those counts are not needed to apply the model. It would not add much to the model size to add these aggregated counts, but could be very useful for some applications of the model.

        def run(data: RDD[LabeledPoint]): NaiveBayesModel = {
           :
          // Aggregates term frequencies per label.
          val aggregated = data.map(p => (p.label, p.features)).combineByKey[(Long, DenseVector)](
            createCombiner = (v: Vector) => {
              :
            },
          :
          new NaiveBayesModel(labels, pi, theta, modelType) // <- please include "aggregated" here.
        }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            barrybecker4 Barry Becker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: