Skip to content

Implementation for the Naive bayesian classifier algorithm

Notifications You must be signed in to change notification settings

goglue/bayesian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Naive Bayesian library for Go

Build Status Coverage Status GoDoc

  • Install
    go get github.com/goglue/bayesian
  • Usage
import "github.com/goglue/bayesian"

func main() {
        // new structure of the classifier
        classifier := bayesian.New()
        classes := []string{"laptops", "computers"}
        
        // add classes to the classifier
        classifier.AddClasses(classes)
        
        // - teach laptops class
        classifier.Learn("laptops", "wifi")
        classifier.Learn("laptops", "wifi")
        classifier.Learn("laptops", "ram")
        classifier.Learn("laptops", "hdd")
        
        // - teach computers class (LearnBulk)
        comLearnings := []string{"wifi", "monitor", "monitor", "ram", "hdd"}
        classifier.LearnBulk("computers", comLearnings)
        
        // setup is done, now get the scores of a given docs
        nodes := []string{"wifi", "ram", "hdd"}
        scores := classifier.Probability(nodes)
        /*
        scores :
        map[laptops:0.7575757575757576 computers:0.24242424242424246]
        */
}
  • Frequency table You can implement this interface and set the classifier storage to it
type ClassFrequencyTable interface {
        Classes() []string
        AddClasses([]string) error
        IncrementNodeFrequency(cls string, node string, i uint) error
        IncrementBulkNodeFrequencies(cls string, node []string) error
        NodeFrequencyInClass(class string, node string) uint
        TotalClassNodesFrequencies() map[string]uint
        AllNodesFrequencies() uint
}

classifier.SetStorage(someRandomStorage)

About

Implementation for the Naive bayesian classifier algorithm

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages