func TestStringsIsContain(t *testing.T) { ss := tekstus.Strings{ "a", "b", "c", "d", } ss2 := []string{ "a", "b", "c", "d", } // Testing true positive got := tekstus.StringsIsContain(ss, "a") assert(t, true, got, true) // Testing true negative got = tekstus.StringsIsContain(ss, "e") assert(t, false, got, true) // Testing true positive got = tekstus.StringsIsContain(ss2, "a") assert(t, true, got, true) // Testing true negative got = tekstus.StringsIsContain(ss2, "e") assert(t, false, got, true) }
/* Classify return the prediction of one sample. */ func (runtime *Runtime) Classify(data *tabula.Row) (class string) { node := runtime.Tree.Root nodev := node.Value.(NodeValue) for !nodev.IsLeaf { if nodev.IsContinu { splitV := nodev.SplitV.(float64) attrV := (*data)[nodev.SplitAttrIdx].Float() if attrV < splitV { node = node.Left } else { node = node.Right } } else { splitV := nodev.SplitV.([]string) attrV := (*data)[nodev.SplitAttrIdx].String() if tekstus.StringsIsContain(splitV, attrV) { node = node.Left } else { node = node.Right } } nodev = node.Value.(NodeValue) } return nodev.Class }