예제 #1
0
        public TitanicNode BuildDecisionTree(List <string> targetFieldNames, List <Passenger> trainData)
        {
            var root = new TitanicNode
            {
                FieldName = "Root",
                Count     = trainData.Count,

                CountYes = trainData.Where(x => x.Survived == 1).Count(),
                DataSet  = trainData
            };

            BuildChildNode(targetFieldNames, root);

            return(root);
        }
예제 #2
0
        public void BuildChildNode(string pFieldName, TitanicNode parent)
        {
            var listOfDistinData = parent.DataSet.Select(x => UnitTest1.GetPropValue(x, pFieldName)).Distinct();

            foreach (var node1 in listOfDistinData)
            {
                var node_1_list = parent.DataSet.Where(x => UnitTest1.GetPropValue(x, pFieldName).Equals(node1)).ToList();
                var n1          = new TitanicNode
                {
                    FieldName = string.Format("{0}.{1}", pFieldName, node1),
                    Count     = node_1_list.Count,
                    CountYes  = node_1_list.Where(x => x.Survived == 1).Count(),
                    DataSet   = node_1_list,
                };
                parent.Children.Add(n1);
            }
        }
예제 #3
0
        public void BuildChildNode(List <string> pFieldNames, TitanicNode parent)
        {
            if (pFieldNames.Count == 0)
            {
                return;
            }

            var pFieldName = pFieldNames.First();

            pFieldNames = pFieldNames.Skip(1).ToList();

            BuildChildNode(pFieldName, parent);
            foreach (var item in parent.Children)
            {
                BuildChildNode(pFieldNames, item);
            }
        }
예제 #4
0
        public TitanicNode BuildDecisionTree(List <Passenger> trainData)
        {
            var root = new TitanicNode
            {
                FieldName = "Root",
                Count     = trainData.Count,

                CountYes = trainData.Where(x => x.Survived == 1).Count(),
                DataSet  = trainData
            };

            //BuildChildNode<Outlook>(root, "Outlook", dataSet);

            BuildChildNode <Gender>("Sex", root);
            foreach (var item in root.Children)
            {
                BuildChildNode <FamilySize>("FamilySize", item);

                foreach (var item2 in item.Children)
                {
                    BuildChildNode <Embarked>("Embarked", item2);

                    foreach (var item3 in item2.Children)
                    {
                        BuildChildNode <Mother>("Mother", item3);
                        foreach (var item4 in item3.Children)
                        {
                            BuildChildNode <AgeOrdinal>("AgeOrdinal", item4);

                            foreach (var item5 in item4.Children)
                            {
                                BuildChildNode <Titles>("Title", item5);

                                foreach (var item6 in item5.Children)
                                {
                                    BuildChildNode <CabinType>("CabinType", item6);
                                }
                            }
                        }
                    }
                }
            }

            return(root);
        }
예제 #5
0
        public void BuildChildNode <E>(string pFieldName, TitanicNode parent)
            where E : struct, IComparable, IFormattable, IConvertible
        {
            foreach (var node1 in Enum.GetValues(typeof(E)))
            {
                var e           = (E)node1;
                var node_1_list = parent.DataSet.Where(x => UnitTest1.GetPropValue(x, pFieldName).Equals(e)).ToList();

                var n1 = new TitanicNode
                {
                    FieldName = e.ToString(),
                    Count     = node_1_list.Count,
                    CountYes  = node_1_list.Where(x => x.Survived == 1).Count(),
                    DataSet   = node_1_list,
                };
                parent.Children.Add(n1);
                //yield return n1;

                //if (n1.CountYes == 0) break;
                //if (pFieldName == "") break;
                //if (pFieldName == "") break;
                //n1.Children.AddRange(BuildChildNode<Humanity>("Humanity", node_1_list));
            }
        }