class

Stochasta::Bayes::NaiveClassifier(C, F)

Inherits Reference < Object

Multinomial/Categorical Naive Bayes Classifier C is the Class type, F is the Feature type

Constructors

Instance methods

class_counts
Source
class_counts=(class_counts : Hash(C, Int32))
Source
feature_counts
Source
feature_counts=(feature_counts : Hash(C, Hash(F, Int32)))
Source
predict(features : Enumerable(F)) : C

Predicts the most likely class for the given features Uses log probabilities to prevent underflow, and Laplace smoothing (+1)

Source
predict_probabilities(features : Enumerable(F)) : Hash(C, Float64)

Computes probability distribution over all classes for the given features

Source
total_samples
Source
total_samples=(total_samples : Int32)
Source
train(features : Enumerable(F), label : C)

Trains the classifier on a single sample of features with its label

Source
vocabulary
Source
vocabulary=(vocabulary : Set(F))
Source