Exemple #1
0
func ClassifyNB(vec2Classify []int, p0Vec []float64, p1Vec []float64, pClass1 float64) int {
	p1 := calc.MultipyIntVec(vec2Classify, p1Vec)
	p0 := calc.MultipyIntVec(vec2Classify, p0Vec)
	p1Val := calc.SumFloat(p1)
	p0Val := calc.SumFloat(p0)
	p1Val += math.Log(pClass1)
	p0Val += math.Log(1.0 - pClass1)

	if p1Val > p0Val {
		return 1
	} else {
		return 0
	}
}
Exemple #2
0
func Test_MultipyIntVec(t *testing.T) {
	a := []int{1, 2, 3}
	b := []float64{2.25, 3.14, 4.67}
	result := calc.MultipyIntVec(a, b)

	if len(result) != len(a) {
		t.Fatalf("Multipy to get wrong size")
	}
}