public DTreeNode GetSplitingFeature(DTreeNode currentNode) { double maxInformationGain = -1000000; DTreeNode splitNode = null; string[][] currentOperationData = trainingDataInstance.GetDataInstances(currentNode.previousFeatureValues); List <string> featureList = GetFeatureList(currentOperationData[0]); foreach (string featureName in featureList) { List <string[]> featureData = GetFeatureData(currentOperationData, featureName); DTreeNode node = new DTreeNode(); node.spliteFeatureName = featureData[0][0]; featureData.RemoveAt(0); node.ExecuteNode(featureData); node.clearDataList(); if (node.entropy == 0.0) { splitNode = currentNode; splitNode.entropy = node.entropy; splitNode.className = node.className; } if (node.informationGain > maxInformationGain) { maxInformationGain = node.informationGain; splitNode = node; } } return(splitNode); }
private double createChildNodesAndGetChildEntropy() { List <string> featureData = GetDistinctFeatureData(); double childEntropy = 0; if (featureData.Count > 1) { foreach (string data in featureData) { DTreeNode childNode = new DTreeNode(); childNode.spliteFeatureValue = data; List <string[]> childData = GetChildNodeData(data); childNode.ExecuteNode(childData); this.childrenNodes.Add(childNode); double factor = (double)childData.Count / this.nodeDataInstance.Count; childEntropy += factor * childNode.entropy; } } return(childEntropy); }