示例#1
0
 private DecisionTreeOutputProperties CloneOutputProperties(DecisionTreeOutputProperties outputProperties)
 {
     return(new DecisionTreeOutputProperties()
     {
         DataCount = outputProperties.DataCount,
         OutputDistribution = outputProperties.OutputDistribution.ToDictionary(x => x.Key, x => x.Value)
     });
 }
示例#2
0
        Dictionary <FeatureValue, TreeNode> BranchContinious(Feature feature, IQueryable <T> data, TreeNode parentNode, out double splitQuality)
        {
            IQueryable <InputOutputPair> orderedInputOutput = BranchContiniousData(feature, data);

            var lowerNode = new DecisionTreeOutputProperties()
            {
                DataCount          = 0,
                OutputDistribution = (parentNode.OutputProperties as DecisionTreeOutputProperties).OutputDistribution.ToDictionary(x => x.Key, x => 0)
            };
            var higherNode      = CloneOutputProperties(parentNode.OutputProperties as DecisionTreeOutputProperties);
            var maxSplitQuality = double.MinValue;
            DecisionTreeOutputProperties maxLowerNode = null;
            object limitInput = null;

            foreach (InputOutputPair value in orderedInputOutput)
            {
                lowerNode.DataCount++;
                higherNode.DataCount--;
                lowerNode.OutputDistribution[value.Output]++;
                higherNode.OutputDistribution[value.Output]--;
                var tempSplitQuality = options.SplitQualifier(lowerNode) * lowerNode.DataCount + options.SplitQualifier(higherNode) * higherNode.DataCount;
                if (tempSplitQuality > maxSplitQuality)
                {
                    maxSplitQuality = tempSplitQuality;
                    maxLowerNode    = CloneOutputProperties(lowerNode);
                    limitInput      = value.Input;
                }
            }
            splitQuality = maxSplitQuality;
            if (maxLowerNode == null)
            {
                return(new Dictionary <FeatureValue, TreeNode>());
            }


            var result = new Dictionary <FeatureValue, TreeNode>();

            result.Add(new ContiniousFeatureValue()
            {
                To = limitInput as IComparable,
            },
                       new TreeNode()
            {
                OutputProperties = lowerNode, Parent = parentNode
            });
            result.Add(new ContiniousFeatureValue()
            {
                From = limitInput as IComparable,
            },
                       new TreeNode()
            {
                OutputProperties = higherNode, Parent = parentNode
            });
            return(result);
        }