Coder Social home page Coder Social logo

bayesian's Introduction

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.