Sha256: fa49923c6843176166cbc3fafe39dc1ba1a3fb4272da2e867319c5c447f62c7b

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

#include "multinomial_bayes_classifier.h"
#include "data_set/data_set.h"
#include <math.h>

double Classifier::MultinomialBayesClassifier::score(DataSet::Category *category, DataSet::Example *example) {

}

void Classifier::MultinomialBayesClassifier::prepare() {
  numeric_feature_probabilities.resize(data_set->categories_size() + 1);
  nominal_feature_probabilities.resize(data_set->categories_size() + 1);
  DataSet::NumericFeature *numeric_feature = NULL;
  DataSet::NominalFeature *nominal_feature = NULL;
  int feature_count = data_set->features.size();
  double category_sum = 0.0;
  
  data_set->count();
  
  // determine the category probabilities for each feature
  for(int i = 1; i <= data_set->categories_size(); i++) {
    numeric_feature_probabilities[i].reserve(feature_count);
    nominal_feature_probabilities[i].reserve(feature_count);
    
    // sum the counts of each numeric feature for this category
    category_sum = 0.0
    for(int j = 0; j < numeric_features.size(); j++)
      category_sum += numeric_features[j]->category_sum(i);
    category_sum += numeric_features.size();
    
    // weight each numeric feature only by the number of other numeric features; nominal features are handled separately
    for(int j = 0; j < numeric_features.size(); j++)
      numeric_feature_probabilities[i][j] = (1.0 + numeric_features[j]->category_sum(i)) / (category_sum);
    
    // each value of a nominal feature is treated as if it were another feature in itself
    for(int j = 0; j < nominal_features.size(); j++) {
      nominal_feature = nominal_features[j];
      nominal_feature_probabilities[j].resize(nominal_feature->values.size());
    }
  }
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
thera-0.0.8 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp
thera-0.0.7 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp
thera-0.0.6 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp
thera-0.0.5 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp
thera-0.0.4 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp
thera-0.0.3 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp
thera-0.0.2 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp
thera-0.0.1 lib/quarry/src/classifier/multinomial_bayes/multinomial_bayes_classifier.cpp