public static void Main(string[] args) { Process p = Process.GetCurrentProcess(); ShowWindow(p.MainWindowHandle, 3); //SW_MAXIMIZE = 3 Console.WriteLine("reading train data..."); StarterClass s = new StarterClass(); DataTable dt = s.readCSVFile("zoo.data"); List <string> autompg_data = new List <string>(); Console.WriteLine("Reading and cleaning train data\n..."); DataHolder dh = new DataHolder(dt, null); Console.WriteLine("finished reading and cleaning data\nBuilding tree..."); SimpleNode node = s.buildtree(null, dh, null, null); Console.WriteLine("built tree\nreading test data..."); // validation begins DataTable autompg_test = s.readCSVFile("zoo.test"); //object classifiedNode = null; Console.WriteLine("finished reading and cleaning test\nstarting classification..."); Dictionary <int, string> testingNodesList = new Dictionary <int, string>(); Dictionary <int, string> classifiedNodesList = new Dictionary <int, string>(); int i = 0; foreach (DataRow datarow in autompg_test.Rows) { testingNodesList[i] = (string)datarow[datarow.ItemArray.Length - 1]; var classifiedNode = s.classify(datarow, node); classifiedNodesList[i] = classifiedNode is SimpleNode ? (((SimpleNode)classifiedNode).Name) : (string)classifiedNode; Console.WriteLine(string.Join(",", datarow.ItemArray) + " " + classifiedNodesList[i]); i++; } Console.Write("\nfinished classifying\ncalculating accuracy..."); int predictedCorrectValues = 0; for (int m = 0; m < testingNodesList.Count; m++) { if (testingNodesList[m] == classifiedNodesList[m]) { predictedCorrectValues += 1; } } double accuracy = 0; if (testingNodesList.Count != 0) { accuracy = (float)(predictedCorrectValues) / testingNodesList.Count * 100; } Console.Write("Found Accuracy:" + accuracy + " %"); Console.ReadKey(); }
public double set_gains(string inp_feature) { double sum_of_entropies_weighted_by_proportion = 0; int s_dataset = Dataset.Rows.Count; foreach (string unique_feature_value in Feature_uniqueValues[inp_feature]) { DataTable temp_newds = getSubset(unique_feature_value, inp_feature); int s_newds = temp_newds.Rows.Count; double e_of_newds = 0.0; double proportion = 0; if (s_newds != 0) { proportion = (double)(s_newds) / s_dataset; e_of_newds = StarterClass.get_entropy(temp_newds, null); } sum_of_entropies_weighted_by_proportion += proportion * e_of_newds; } double infogain = Entropy - sum_of_entropies_weighted_by_proportion; return(infogain); }