private void zoo_example() { string path = @"zoo.txt"; Headers = new string[] { "Hair", "Feathers", "Eggs", "Milk", "Airborne", "Aquatic", "Predator", "Toothed", "Backbone", "Breathes", "Venomous", "Fins", "Legs", "Tail", "Domestic", "Catsize" }; Result = "Animal type"; List <string[]> rows = new List <string[]>(); List <string[]> dummy = new List <string[]>(); foreach (var animalData in File.ReadAllLines(path)) { List <string> data = new List <string>(); string[] line = animalData.Split(','); for (int i = 0; i < line.Length; ++i) { if (i == 13 || i == 17 || i == 0) { data.Add(line[i]); } else { data.Add(BoolParser.Parse(line[i]).ToString()); } } dummy.Add(data.ToArray()); data.RemoveAt(0); rows.Add(data.ToArray()); } UpdateDataBaseZoo(dummy); tcMain.Clear(); tree = DecisionTreeTools.BuildTree(rows); DecisionTreeTools.Prune(tree.NextFalseNode.NextTrueNode.NextFalseNode.NextTrueNode, 1.01); DecisionTreeTools.Prune(tree.NextFalseNode.NextTrueNode.NextTrueNode.NextFalseNode, 1.01); PrintTree(tree); listBoxZoo.Items.Clear(); listBoxZoo.Items.Add( "1 -- (41) aardvark, antelope, bear, boar, buffalo, calf, cavy, cheetah, deer, dolphin, elephant, fruitbat, giraffe, girl, goat, gorilla, hamster, hare, leopard, lion, lynx, mink, mole, mongoose, opossum, oryx, platypus, polecat, pony, porpoise, puma, pussycat, raccoon, reindeer, seal, sealion, squirrel, vampire, vole, wallaby,wolf "); listBoxZoo.Items.Add( "2 -- (20) chicken, crow, dove, duck, flamingo, gull, hawk, kiwi, lark, ostrich, parakeet, penguin, pheasant, rhea, skimmer, skua, sparrow, swan, vulture, wren "); listBoxZoo.Items.Add("3 -- (5) pitviper, seasnake, slowworm, tortoise, tuatara"); listBoxZoo.Items.Add( "4 -- (13) bass, carp, catfish, chub, dogfish, haddock, herring, pike, piranha, seahorse, sole, stingray, tuna "); listBoxZoo.Items.Add("5 -- (4) frog, frog, newt, toad "); listBoxZoo.Items.Add("6 -- (8) flea, gnat, honeybee, housefly, ladybird, moth, termite, wasp "); listBoxZoo.Items.Add( "7 -- (10) clam, crab, crayfish, lobster, octopus, scorpion, seawasp, slug, starfish, worm"); listBoxZoo.Visibility = Visibility.Visible; }
private void simple_example() { string path = @"decision_tree_example.txt"; Headers = new string[] { "Refferer", "Location", "Read FAQ", "Pages viewed" }; Result = "Service"; List <string[]> rows = new List <string[]>(); foreach (var word in File.ReadAllLines(path)) { rows.Add(word.Split('\t')); } tcMain.Clear(); tree = DecisionTreeTools.BuildTree(rows); PrintTree(tree); UpdateDataBaseSimpleExample(rows); listBoxZoo.Visibility = Visibility.Hidden; }