Ejemplo n.º 1
0
			})
		})

	})

	Describe("#Decide", func() {

		var input []string

		Describe("when the node value is a boolean", func() {
			It("returns the node value", func() {
				gomock.InOrder(
					mockBinaryTree.EXPECT().Value().Return(true),
					mockBinaryTree.EXPECT().Value().Return(false),
				)
				Expect(myTree.Decide(input)).To(Equal(true))
				Expect(myTree.Decide(input)).To(Equal(false))
			})
		})

		Describe("when the node value is a string label", func() {
			var (
				mockDecisionTree *mdt.MockInterface
			)

			BeforeEach(func() {
				mockDecisionTree = mdt.NewMockInterface(mockCtrl)
			})

			Context("when the node label is in the input set", func() {
				It("recurses right", func() {
Ejemplo n.º 2
0
		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))
			Expect(myTree.Right().Value()).To(Equal(false))
		})
	})

	Describe("Making a decision", func() {
		It("decides false in the right cases", func() {
			Expect(myTree.Decide([]string{"0", "1"})).To(Equal(true))
		})
		It("decides true in the right cases", func() {
			Expect(myTree.Decide([]string{"2"})).To(Equal(false))
		})
	})

})