bayesian

Naive Bayesian Classification for Golang.

4 years after

Naive Bayesian Classification

Perform naive Bayesian classification into an arbitrary number of classes on sets of strings.

Copyright (c) 2011. Jake Brukhman. ([email protected]). All rights reserved. See the LICENSE file for BSD-style license.


Background

See code comments for a refresher on naive Bayesian classifiers.


Installation

Using the go command:

$ go get github.com/jbrukh/bayesian
$ go install !$

Documentation

See the GoPkgDoc documentation here.


Features

  • Conditional probability and "log-likelihood"-like scoring.
  • Underflow detection.
  • Simple persistence of classifiers.
  • Statistics.

Example

To use the classifier, first you must create some classes and train it:

import . "bayesian"

const (
    Good Class = "Good"
    Bad Class = "Bad"
)

classifier := NewClassifier(Good, Bad)
goodStuff := []string{"tall", "rich", "handsome"}
badStuff  := []string{"poor", "smelly", "ugly"}
classifier.Learn(goodStuff, Good)
classifier.Learn(badStuff,  Bad)

Then you can ascertain the scores of each class and the most likely class your data belongs to:

scores, likely, _ := classifier.LogScores(
                        []string{"tall", "girl"}
                     )

Magnitude of the score indicates likelihood. Alternatively (but with some risk of float underflow), you can obtain actual probabilities:

probs, likely, _ := classifier.ProbScores(
                        []string{"tall", "girl"}
                     )

Use wisely.

Related Repositories

Probabilistic-Programming-and-Bayesian-Methods-for-Hackers

Probabilistic-Programming-and-Bayesian-Methods-for-Hackers

aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probab ...

Bayesian-Modelling-in-Python

Bayesian-Modelling-in-Python

A python tutorial on bayesian modeling techniques (PyMC3) ...

bayesian-belief-networks

bayesian-belief-networks

Pythonic Bayesian Belief Network Package, supporting creation of and exact infer ...

bayesian-bandit.js

bayesian-bandit.js

Bayesian bandit implementation for Node and the browser. ...

bayesian-quadrature

bayesian-quadrature

Bayesian quadrature ...