static void spiral () { Dataset train = Dataset.GenerateSpiral(0, 0, 1, 1, 0.1f, 1000, 10, 100); train.WriteCSV("./data/spiral_train.csv", true); Dataset test = Dataset.CloneInputSet(train); DecisionForest df = new DecisionForest(train, 10, 30, 20); for (int row = 0; row < test.Inputs.Count; row++) { List<float> outputs = new List<float>(); outputs.Add(df.Classify(test.Inputs[row])); test.Outputs.Add(outputs); } test.WriteCSV("./data/spiral_test.csv", true); }
static void ocr () { OCRDataset train = new OCRDataset(); train.ReadTrainCSV("./data/ocr_train.csv"); OCRDataset test = new OCRDataset(); test.ReadTestCSV("./data/ocr_test.csv"); DecisionForest df = new DecisionForest(train, 20000, 1000, 10000); for (int row = 0; row < test.Inputs.Count; row++) { Console.WriteLine("i: " + row + "/" + test.Inputs.Count); List<float> outputs = new List<float>(); outputs.Add(df.Classify(test.Inputs[row])); test.Outputs.Add(outputs); } test.WriteTestCSV("./data/ocr_est.csv"); }
static void fin() { Dataset train = new Dataset(); train.ReadCSV("./data/validate.win", 2000, false); Dataset test = new Dataset(); test.Inputs.Add(train.Inputs[train.Inputs.Count - 1]); DecisionForest df = new DecisionForest(train, 10, 500, 500); for (int row = 0; row < test.Inputs.Count; row++) { Console.WriteLine("i: " + row + "/" + test.Inputs.Count); List<float> outputs = new List<float>(); outputs.Add(df.Classify(test.Inputs[row])); test.Outputs.Add(outputs); } test.WriteCSV("./data/est.win", false); }
public static float Fitness (DecisionForest DecisionForest, Dataset Validation) { int correct = 0; for (int row = 0; row < Validation.Inputs.Count; row++) { if (Validation.Outputs[row][0] == DecisionForest.Classify(Validation.Inputs[row])) { correct++; } } return ((float)correct) / ((float)Validation.Inputs.Count); }