RF.go icon indicating copy to clipboard operation
RF.go copied to clipboard

forest.Predicate does not return a value

Open NightlySide opened this issue 3 years ago • 1 comments

I'm following the iris example and built a similar forest for malware detection. My inputs is a vector of ints and the target a string.

However when I use forest.Predicate(inputs) I don't get any output (empty string).. Is it something intended?

Here is a snippet of my code :

        // split train and test data
	Logger.Debug("splitting data in training and testing")
	train_input := [][]interface{}{}
	test_input := [][]interface{}{}

	train_target := []string{}
	test_target := []string{}

	for i := 0; i < len(inputs); i++ {
		input := inputs[i]
		target := targets[i]

		test := rand.Float64()
		if test > TRAIN_TEST_PERCENT {
			test_input = append(test_input, input)
			test_target = append(test_target, target)
		} else {
			train_input = append(train_input, input)
			train_target = append(train_target, target)
		}
	}
	Logger.Debugf("Got %d training and %d testing samples over %d samples", len(train_input), len(test_input), len(inputs))

	// create classifier
	Logger.Debug("training the forest")
	forest := RF.DefaultForest(train_input, train_target, 100) //100 trees
	RF.DumpForest(forest, filepath.Join("data", "model.ml"))

	// get stats for the classifier
	Logger.Debug("gathering stats")
	err_count := 0.0
	for i := 0; i < len(test_input); i++ {
		output := forest.Predicate(test_input[i])
		expect := test_target[i]
		Logger.Tracef("Out: %s | Expected: %s", output, expect)
		if output != expect {
			err_count += 1
		}
	}
	Logger.Infof("success rate: %f", 1.0-err_count/float64(len(test_input)))

NightlySide avatar Jul 07 '22 14:07 NightlySide

Ok I fixed it.. The issue is the fact the forest only accept strings or float64 as inputs

NightlySide avatar Jul 07 '22 14:07 NightlySide