bayes

package module
v0.0.0-...-fbdd272 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2017 License: MIT Imports: 10 Imported by: 1

README

bayes

Simple Bayes Classifier Package

http://godoc.org/github.com/barnjamin/bayes

Documentation

Overview

Example
data, labels := generateData()

nb := New()
if err := nb.Fit(data, labels); err != nil {
	log.Printf("Failed to fit data: %+v", err)
}

for idx, label := range labels {
	prediction := nb.Predict(data[idx])
	log.Printf("Expected: %s Got: %s", label, prediction)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CrossValidate

func CrossValidate(data [][]float64, labels []string, percentage float64) float64

func Split

func Split(data [][]float64, labels []string, percentage float64) ([][]float64, []string, [][]float64, []string)

Types

type NaiveBayes

type NaiveBayes struct {
	Stats     map[string][]Stats
	Grouped   map[string][][]float64
	ColumnCnt int
	SampleCnt int
	sync.Mutex
}

func Load

func Load(r io.Reader) (*NaiveBayes, error)

func New

func New() *NaiveBayes

func (*NaiveBayes) Append

func (n *NaiveBayes) Append(data []float64, label string) error

Add new observation dynamically Must call ComputeStats before calling Predict again

func (*NaiveBayes) ComputeStats

func (n *NaiveBayes) ComputeStats()

func (*NaiveBayes) Dump

func (n *NaiveBayes) Dump(w io.Writer) error

func (*NaiveBayes) Fit

func (n *NaiveBayes) Fit(data [][]float64, labels []string) error

func (*NaiveBayes) Predict

func (n *NaiveBayes) Predict(data []float64) string

func (*NaiveBayes) PredictProbability

func (n *NaiveBayes) PredictProbability(data []float64) map[string]float64

type Stats

type Stats struct {
	Mean float64
	Std  float64
}

func CalculateStats

func CalculateStats(vals []float64) Stats

func (*Stats) CalculateProbability

func (s *Stats) CalculateProbability(val float64) float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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