func (self *PredictionForest) Train(inputLog il.Interface) { for _, key := range inputLog.Keys() { var newTree dt.Interface newTree = dt.New() newTree.Train(inputLog, key) self.Trees[key] = newTree } }
maxEntropyCall = inputLog.EXPECT().MaxEntropy(targetKey) }) Describe("when there are no features left to decide on", func() { BeforeEach(func() { maxEntropyCall.Return(targetKey) inputLog.EXPECT().Len().Return(7) keyCountCall = inputLog.EXPECT().KeyCount(targetKey) }) Context("when there are more occurances of the target key than absences", func() { It("decides with a value of true", func() { keyCountCall.Return(5) mockBinaryTree.EXPECT().Set(true) myTree.Train(inputLog, targetKey) }) }) Context("when there are more absences of the target key than occurances", func() { It("decides with a value of false", func() { keyCountCall.Return(3) mockBinaryTree.EXPECT().Set(false) myTree.Train(inputLog, targetKey) }) }) }) Describe("when there are still features to decide on", func() { BeforeEach(func() { nextKey = "the next key to decide on"
var myTree dt.Interface BeforeEach(func() { id3InputSet = il.InputLog{ {"1", "3"}, {"0", "1", "3"}, {"1", "3"}, {"0", "1", "3"}, {"1", "2"}, {"0", "1", "2"}, {}, {"0"}, } myTree = dt.New() myTree.Train(il.Interface(id3InputSet), "3") }) Describe("Training a Decision Tree", func() { It("it uses ID3 to maximize entropy", func() { Expect(myTree.Value()).To(Equal("2")) Expect(myTree.Left().Value()).To(Equal("1")) }) It("doesn't continue building a branch if a decision can be made", func() { Expect(myTree.Left().Right().Right()).To(BeNil()) }) It("builds a tree with the right decisions", func() { Expect(myTree.Left().Right().Value()).To(Equal(true)) Expect(myTree.Left().Left().Value()).To(Equal(false))