private void FormGini_Load(object sender, EventArgs e) { FormUtama form = (FormUtama)this.Owner; list = form.listOfPerson; Total(); GiniT yesF1 = Feat1("YES"); listGiniF1.Add(yesF1); GiniT noF1 = Feat1("NO"); listGiniF1.Add(noF1); GiniT yesF2 = Feat2("YES"); listGiniF2.Add(yesF2); GiniT noF2 = Feat2("YES"); listGiniF2.Add(noF2); yesF1.CalcGini(); noF1.CalcGini(); yesF2.CalcGini(); noF2.CalcGini(); textBoxOutput.Text = yesF1.Gini.ToString(); textBox1.Text = GiniChild.CalcGiniChild(listGiniF2, total).ToString(); //GiniChild.CalcGiniChild(listGiniF1, total).ToString(); // }
private List <GiniT> Feat3(string node) { List <GiniT> listOfGini = new List <GiniT>(); list.Sort(delegate(Person x, Person y) { if (x.Feat3 == 0 && y.Feat3 == 0) { return(0); } else if (x.Feat3 == 0) { return(-1); } else if (y.Feat3 == 0) { return(1); } else { return(x.Feat3.CompareTo(y.Feat3)); } }); int split = (list[0].Feat3 + list[1].Feat3) / 2; for (int i = 2; i < list.Count; i++) { int sameSplit = (list[i - 1].Feat3 + list[i].Feat3) / 2; if (split != sameSplit) { foreach (Person person in list) { if (node == "<=") { if (person.Feat3 <= split && person.Classif == "C0") { c0++; } else if (person.Feat3 <= split && person.Classif == "C1") { c1++; } } else { if (person.Feat3 > split && person.Classif == "C0") { c0++; } else if (person.Feat3 > split && person.Classif == "C1") { c1++; } } } GiniT gini = new GiniT(node + " " + split.ToString(), c0, c1); gini.CalcGini(); listOfGini.Add(gini); c0 = 0; c1 = 0; split = sameSplit; } } return(listOfGini); }