naive_bayes

package
v0.11.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 11 Imported by: 11 modules, 11 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NaiveBayesClassifier

type NaiveBayesClassifier struct {
	Words               map[string]map[string]int
	TotalWords          int
	CategoriesDocuments map[string]int
	TotalDocuments      int
	CategoriesWords     map[string]int
	Threshold           float64
}

NaiveBayesClassifier is what we use to classify documents

func New

func New(threshold float64) *NaiveBayesClassifier

create and initialize the classifier

func NewClassifierFromFile

func NewClassifierFromFile(path string) (*NaiveBayesClassifier, error)

create and initialize the classifier from a file

func NewClassifierFromFileData

func NewClassifierFromFileData(data []byte) (*NaiveBayesClassifier, error)

create and initialize the classifier from a file data

func NewClassifierWithReader

func NewClassifierWithReader(reader io.Reader) (*NaiveBayesClassifier, error)

create and initialize the classifier from a file data

func (*NaiveBayesClassifier) Classify

func (c *NaiveBayesClassifier) Classify(document string) (category string)

Classify a document

func (*NaiveBayesClassifier) Evaluate

func (c *NaiveBayesClassifier) Evaluate(train, test []mlutils.LabeledDocument)

func (*NaiveBayesClassifier) Fit

func (c *NaiveBayesClassifier) Fit(data map[string][]string)

func (*NaiveBayesClassifier) Probabilities

func (c *NaiveBayesClassifier) Probabilities(document string) (p map[string]float64)

Probabilities of each category

func (*NaiveBayesClassifier) SaveClassifierToFile

func (c *NaiveBayesClassifier) SaveClassifierToFile(path string) error

save the classifier to a file

type Sorted

type Sorted struct {
	Category    string
	Probability float64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL