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)
}
Index ¶
- func CrossValidate(data [][]float64, labels []string, percentage float64) float64
- func Split(data [][]float64, labels []string, percentage float64) ([][]float64, []string, [][]float64, []string)
- type NaiveBayes
- func (n *NaiveBayes) Append(data []float64, label string) error
- func (n *NaiveBayes) ComputeStats()
- func (n *NaiveBayes) Dump(w io.Writer) error
- func (n *NaiveBayes) Fit(data [][]float64, labels []string) error
- func (n *NaiveBayes) Predict(data []float64) string
- func (n *NaiveBayes) PredictProbability(data []float64) map[string]float64
- type Stats
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CrossValidate ¶
Types ¶
type NaiveBayes ¶
type NaiveBayes struct {
Stats map[string][]Stats
Grouped map[string][][]float64
ColumnCnt int
SampleCnt int
sync.Mutex
}
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) Predict ¶
func (n *NaiveBayes) Predict(data []float64) string
func (*NaiveBayes) PredictProbability ¶
func (n *NaiveBayes) PredictProbability(data []float64) map[string]float64
Click to show internal directories.
Click to hide internal directories.