Documentation ¶
Index ¶
- type BernoulliNBClassifier
- func (nb *BernoulliNBClassifier) Fit(X base.FixedDataGrid) error
- func (nb *BernoulliNBClassifier) GetMetadata() base.ClassifierMetadataV1
- func (nb *BernoulliNBClassifier) Load(filePath string) error
- func (nb *BernoulliNBClassifier) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
- func (nb *BernoulliNBClassifier) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
- func (nb *BernoulliNBClassifier) PredictOne(vector [][]byte) string
- func (nb *BernoulliNBClassifier) Save(filePath string) error
- func (nb *BernoulliNBClassifier) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
- func (nb *BernoulliNBClassifier) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BernoulliNBClassifier ¶
type BernoulliNBClassifier struct { base.BaseEstimator // contains filtered or unexported fields }
A Bernoulli Naive Bayes Classifier. Naive Bayes classifiers assumes that features probabilities are independent. In order to classify an instance, it is calculated the probability that it was generated by each known class, that is, for each class C, the following probability is calculated.
p(C|F1, F2, F3... Fn)
Being F1, F2... Fn the instance features. Using the bayes theorem this can be written as:
\frac{p(C) \times p(F1, F2... Fn|C)}{p(F1, F2... Fn)}
In the Bernoulli Naive Bayes features are considered independent booleans, this means that the likelihood of a document given a class C is given by:
p(F1, F2... Fn) = \prod_{i=1}^{n}{[F_i \times p(f_i|C)) + (1-F_i)(1 - p(f_i|C)))]}
where
- F_i equals to 1 if feature is present in vector and zero otherwise
- p(f_i|C) the probability of class C generating the feature f_i
For more information:
C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to Information Retrieval. Cambridge University Press, pp. 234-265. http://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html
func NewBernoulliNBClassifier ¶
func NewBernoulliNBClassifier() *BernoulliNBClassifier
Create a new Bernoulli Naive Bayes Classifier. The argument 'classes' is the number of possible labels in the classification task.
func (*BernoulliNBClassifier) Fit ¶
func (nb *BernoulliNBClassifier) Fit(X base.FixedDataGrid) error
Fill data matrix with Bernoulli Naive Bayes model. All values necessary for calculating prior probability and p(f_i)
func (*BernoulliNBClassifier) GetMetadata ¶
func (nb *BernoulliNBClassifier) GetMetadata() base.ClassifierMetadataV1
func (*BernoulliNBClassifier) Load ¶
func (nb *BernoulliNBClassifier) Load(filePath string) error
func (*BernoulliNBClassifier) LoadWithPrefix ¶
func (nb *BernoulliNBClassifier) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
func (*BernoulliNBClassifier) Predict ¶
func (nb *BernoulliNBClassifier) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
Predict is just a wrapper for the PredictOne function.
IMPORTANT: Predict panics if Fit was not called or if the document vector and train matrix have a different number of columns.
func (*BernoulliNBClassifier) PredictOne ¶
func (nb *BernoulliNBClassifier) PredictOne(vector [][]byte) string
Use trained model to predict test vector's class. The following operation is used in order to score each class:
classScore = log(p(c)) + \sum_{f}{log(p(f|c))}
PredictOne returns the string that represents the predicted class.
IMPORTANT: PredictOne panics if Fit was not called or if the document vector and train matrix have a different number of columns.
func (*BernoulliNBClassifier) Save ¶
func (nb *BernoulliNBClassifier) Save(filePath string) error
func (*BernoulliNBClassifier) SaveWithPrefix ¶
func (nb *BernoulliNBClassifier) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
func (*BernoulliNBClassifier) String ¶
func (nb *BernoulliNBClassifier) String() string