Example #1
0
func TestWordsCountMissRate(t *testing.T) {
	data := []string{"A", "B", "C", "D"}
	test := []string{"A", "B", "C", "D"}
	repl := []string{"B", "C", "D", "E"}
	exps := []float64{0.25, 0.5, 0.75, 1.0}

	got, _, _ := tekstus.WordsCountMissRate(data, test)
	assert(t, 0.0, got, true)

	for x, exp := range exps {
		test[x] = repl[x]
		got, _, _ = tekstus.WordsCountMissRate(data, test)
		assert(t, exp, got, true)
	}
}
Example #2
0
/*
CountOOBError process out-of-bag data on tree and return error value.
*/
func (runtime *Runtime) CountOOBError(oob tabula.Claset) (
	errval float64,
	e error,
) {
	// save the original target to be compared later.
	origTarget := oob.GetClassAsStrings()

	if DEBUG >= 2 {
		fmt.Println("[cart] OOB:", oob.Columns)
		fmt.Println("[cart] TREE:", &runtime.Tree)
	}

	// reset the target.
	oobtarget := oob.GetClassColumn()
	oobtarget.ClearValues()

	e = runtime.ClassifySet(&oob)

	if e != nil {
		// set original target values back.
		oobtarget.SetValues(origTarget)
		return
	}

	target := oobtarget.ToStringSlice()

	if DEBUG >= 2 {
		fmt.Println("[cart] original target:", origTarget)
		fmt.Println("[cart] classify target:", target)
	}

	// count how many target value is miss-classified.
	runtime.OOBErrVal, _, _ = tekstus.WordsCountMissRate(origTarget, target)

	// set original target values back.
	oobtarget.SetValues(origTarget)

	return runtime.OOBErrVal, nil
}