예제 #1
0
        public void Expand()
        {
            LearningOpenNode node = _tree.OpenNode() as LearningOpenNode;

            if (node == null)
            {
                throw new Exception("No open node left");
            }

            ItemSet set     = node.LearningSet();
            double  entropy = set.CalEntropy(_goalAttribute);

            if (entropy <= _entropyThreshold || _testAttributeSet.Size() == 0)
            {
                MakeLeafNode(node);
            }
            else
            {
                TestScore testScore = set.BestSplitTest(_testAttributeSet, _goalAttribute);

                if (testScore.Score * set.Size() <= _scoreThreshold)
                { //forward pruning: test does not provide enough information
                    MakeLeafNode(node);
                }
                else
                {
                    MakeTestNode(node, testScore.Test, testScore.Score * set.Size());
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Finds the test on each attribute performing the best split for finding the value of a 'goal'
        /// attribute.
        /// </summary>
        /// <param name="candidateAttributes"></param>
        /// <param name="goalAttribute"></param>
        /// <returns></returns>
        public IEnumerable <TestScore> BestSplitTests(AttributeSet candidateAttributes, SymbolicAttribute goalAttribute)
        {
            if (candidateAttributes == null || goalAttribute == null || candidateAttributes.Size() == 0)
            {
                throw new ArgumentNullException();
            }

            List <TestScore> bestScores = new List <TestScore>();

            List <Attribute> attributes = candidateAttributes.GetAttributes().ToList();

            foreach (Attribute attr in attributes)
            {
                bestScores.Add(BestSplitTest(attr, goalAttribute));
            }

            return(bestScores);
        }