public void constructDecisionTree() { DecisionTreeNode a = new DecisionTreeNode(ds); MvcMovie.Models.DataSet bD = new MvcMovie.Models.DataSet(ds.filterTable("Income", "< R15k")); MvcMovie.Models.DataSet cD = new MvcMovie.Models.DataSet(ds.filterTable("Income", "R15k - R35k")); MvcMovie.Models.DataSet dD = new MvcMovie.Models.DataSet(ds.filterTable("Income", "> R35k")); MvcMovie.Models.DataSet eD = new MvcMovie.Models.DataSet(cD.filterTable("CreditHistory", "BAD")); MvcMovie.Models.DataSet fD = new MvcMovie.Models.DataSet(cD.filterTable("CreditHistory", "GOOD")); MvcMovie.Models.DataSet gD = new MvcMovie.Models.DataSet(cD.filterTable("CreditHistory", "UNKNOWN")); MvcMovie.Models.DataSet hD = new MvcMovie.Models.DataSet(dD.filterTable("CreditHistory", "BAD")); MvcMovie.Models.DataSet iD = new MvcMovie.Models.DataSet(dD.filterTable("CreditHistory", "GOOD")); MvcMovie.Models.DataSet jD = new MvcMovie.Models.DataSet(dD.filterTable("CreditHistory", "UNKNOWN")); MvcMovie.Models.DataSet kD = new MvcMovie.Models.DataSet(gD.Copy().filterTable("Debt", "HIGH")); MvcMovie.Models.DataSet lD = new MvcMovie.Models.DataSet(gD.Copy().filterTable("Debt", "LOW")); a.recursivelyConstructDecisionTreeLevels(a); Console.Write("Constructed node b is: "); a.decisionChildren[0].ds.printDataSet(); Console.Write("Manual node b is: "); bD.printDataSet(); Assert.IsTrue(a.decisionChildren[0].ds.isDataSetSame(bD)); Assert.IsTrue(a.decisionChildren[1].ds.isDataSetSame(cD)); Assert.IsTrue(a.decisionChildren[2].ds.isDataSetSame(dD)); Assert.IsTrue(a.decisionChildren[1].decisionChildren[0].ds.isDataSetSame(gD)); Assert.IsTrue(a.decisionChildren[1].decisionChildren[1].ds.isDataSetSame(fD)); Assert.IsTrue(a.decisionChildren[1].decisionChildren[2].ds.isDataSetSame(eD)); Assert.IsTrue(a.decisionChildren[2].decisionChildren[0].ds.isDataSetSame(jD)); Assert.IsTrue(a.decisionChildren[2].decisionChildren[1].ds.isDataSetSame(hD)); Assert.IsTrue(a.decisionChildren[2].decisionChildren[2].ds.isDataSetSame(iD)); Assert.IsTrue(a.decisionChildren[1].decisionChildren[0].decisionChildren[0].ds.isDataSetSame(kD)); Assert.IsTrue(a.decisionChildren[1].decisionChildren[0].decisionChildren[1].ds.isDataSetSame(lD)); }
public void testIsSingleDecision() { DecisionTreeNode a = new DecisionTreeNode(ds); MvcMovie.Models.DataSet d = new MvcMovie.Models.DataSet(a.ds.filterTable("Income", "< R15k")); Console.WriteLine("Single Decision Test: " + d.distinctValues(d.dt, d.dt.Columns.Count - 1).Count); Assert.IsTrue(d.isSingleDecision()); }
public void BaseTearDown() { ds = new MvcMovie.Models.DataSet(); }
public void constructDataSetFromListOfLists() { //Given List <List <String> > listOfLists = new List <List <String> >(); List <String> l1 = new List <String> { "Credit history", "Debt", "Collateral", "Income", "Risk" }; List <String> l2 = new List <String> { "BAD", "HIGH", "NO", "< R15k", "HIGH" }; List <String> l3 = new List <String> { "UNKNOWN", "HIGH", "NO", "R15k - R35k", "HIGH" }; List <String> l4 = new List <String> { "UNKNOWN", "LOW", "NO", "R15k - R35k", "MEDIUM" }; List <String> l5 = new List <String> { "UNKNOWN", "LOW", "NO", "< R15k", "HIGH" }; List <String> l6 = new List <String> { "UNKNOWN", "LOW", "NO", "> R35k", "LOW" }; List <String> l7 = new List <String> { "UNKNOWN", "LOW", "YES", "> R35k", "LOW" }; List <String> l8 = new List <String> { "BAD", "LOW", "NO", "< R15k", "HIGH" }; List <String> l9 = new List <String> { "BAD", "LOW", "YES", "> R35k", "MEDIUM" }; List <String> l10 = new List <String> { "GOOD", "LOW", "NO", "> R35k", "LOW" }; List <String> l11 = new List <String> { "GOOD", "HIGH", "YES", "> R35k", "LOW" }; List <String> l12 = new List <String> { "GOOD", "HIGH", "NO", "< R15k", "HIGH" }; List <String> l13 = new List <String> { "GOOD", "HIGH", "NO", "R15k - R35k", "MEDIUM" }; List <String> l14 = new List <String> { "GOOD", "HIGH", "NO", "> R35k", "LOW" }; List <String> l15 = new List <String> { "BAD", "HIGH", "NO", "R15k - R35k", "HIGH" }; listOfLists.Add(l1); listOfLists.Add(l2); listOfLists.Add(l3); listOfLists.Add(l4); listOfLists.Add(l5); listOfLists.Add(l6); listOfLists.Add(l7); listOfLists.Add(l8); listOfLists.Add(l9); listOfLists.Add(l10); listOfLists.Add(l11); listOfLists.Add(l12); listOfLists.Add(l13); listOfLists.Add(l14); listOfLists.Add(l15); //When MvcMovie.Models.DataSet testDS = new MvcMovie.Models.DataSet(listOfLists); //Then Assert.AreEqual(l1[0], testDS.dt.Columns[0].ColumnName); Assert.AreEqual(l1[4], testDS.dt.Columns[4].ColumnName); Assert.AreEqual(listOfLists[1][0], testDS.dt.Rows[0][0]); Assert.AreEqual(listOfLists[1][3], testDS.dt.Rows[0][3]); Assert.AreEqual(listOfLists[3][0], testDS.dt.Rows[2][0]); Assert.AreEqual(listOfLists[5][1], testDS.dt.Rows[4][1]); }