You can test the milestone by using the -p flag and comparing to mushroom.csv, for instance ./fungi -p -n 10
To test numCorrect, the following code should return 38. If you get 62, you have an error.
attr = "anise" -- replace "anise" with your representation of the anise smell
mushA = [ attr ]
mushB = [] -- has no attributes!
obs = replicate 8 (mushA, Nom) ++ replicate 2 (mushA, NoNom) ++ replicate 60 (mushB, Nom) ++ replicate 30 (mushB, NoNom)
numCorrect attr obs
You should guess anise-smelling mushrooms to be edible, and be right 8 times, and non-anise-smelling mushrooms
to be inedible, and be right 30 times.
If you set attr2 to be your representation of almond smell, numcorrect attr2 obs should give you 0.
You can test buildTree by using the -t flag, for instance ./fungi -t cse_mushrooms.csv. This should result in a tree that corresponds to the following:
1: If the mushroom has a knobbed cap shape go to step 2, otherwise go to step 9.
2: If the mushroom has broad gills go to step 3, otherwise go to step 6.
3: If the mushroom has white spores go to step 4, otherwise go to step 5.
4: Do not eat the mushroom.
5: Eat the mushroom.
6: If the mushroom has white spores go to step 7, otherwise go to step 8.
7: Eat the mushroom.
8: Do not eat the mushroom.
9: If the mushroom has broad gills go to step 10, otherwise go to step 13.
10: If the mushroom has white spores go to step 11, otherwise go to step 12.
11: Eat the mushroom.
12: Do not eat the mushroom.
13: If the mushroom has white spores go to step 14, otherwise go to step 15.
14: Do not eat the mushroom.
15: Eat the mushroom.
To check if your output matches, copy it to a text file and insert line breaks and tabs.
./fungi cse_mushrooms.csv should output the following tree.
You will have an uglier output if you have not completed the full-credit custom Show instance.
1: If the mushroom has a knobbed cap shape go to step 2, otherwise go to step 9.
2: If the mushroom has broad gills go to step 3, otherwise go to step 6.
3: If the mushroom has white spores go to step 4, otherwise go to step 5.
4: Do not eat the mushroom.
5: Eat the mushroom.
6: If the mushroom has white spores go to step 7, otherwise go to step 8.
7: Eat the mushroom.
8: Do not eat the mushroom.
9: If the mushroom has broad gills go to step 10, otherwise go to step 13.
10: If the mushroom has white spores go to step 11, otherwise go to step 12.
11: Eat the mushroom.
12: Do not eat the mushroom.
13: If the mushroom has white spores go to step 14, otherwise go to step 15.
14: Do not eat the mushroom.
15: Eat the mushroom.
Note: This example has a lot of categories with only two options, which will thus have the same number of correct choices. Thus your
program may output a guide that uses the other cap shape, gill shape, or spore color. This largely depends on the order of attributes
in your initial list. It may be simpler to change the order than to check that you have a logically identical tree.
Using the full file, the output of ./fungi is included below. It may be easier to compare your answer to the visual representation.
1: If the mushroom has no odor go to step 2, otherwise go to step 25.
2: If the mushroom has green spores go to step 3, otherwise go to step 4.
3: Do not eat the mushroom.
4: If the mushroom has a yellow cap go to step 5, otherwise go to step 6.
5: Do not eat the mushroom.
6: If the mushroom has a yellow stalk go to step 7, otherwise go to step 8.
7: Do not eat the mushroom.
8: If the mushroom has a conical cap shape go to step 9, otherwise go to step 10.
9: Do not eat the mushroom.
10: If the mushroom has a knobbed cap shape go to step 11, otherwise go to step 22.
11: If the mushroom has broad gills go to step 12, otherwise go to step 13.
12: Eat the mushroom.
13: If the mushroom has a white cap go to step 14, otherwise go to step 17.
14: If the mushroom has a missing stalk go to step 15, otherwise go to step 16.
15: Eat the mushroom.
16: Do not eat the mushroom.
17: If the mushroom has white spores go to step 18, otherwise go to step 21.
18: If the mushroom has a missing stalk go to step 19, otherwise go to step 20.
19: Do not eat the mushroom.
20: Eat the mushroom.
21: Eat the mushroom.
22: If the mushroom has broad gills go to step 23, otherwise go to step 24.
23: Eat the mushroom.
24: Do not eat the mushroom.
25: If the mushroom has a club stalk go to step 26, otherwise go to step 29.
26: If the mushroom has a musty odor go to step 27, otherwise go to step 28.
27: Do not eat the mushroom.
28: Eat the mushroom.
29: If the mushroom has an anise odor go to step 30, otherwise go to step 31.
30: Eat the mushroom.
31: If the mushroom has an almond odor go to step 32, otherwise go to step 33.
32: Eat the mushroom.
33: Do not eat the mushroom.
./fungi -c cse_mushrooms.csv with full-credit common subexpression elimination
Start on line 7
7: If the mushroom has a knobbed cap shape go to step 5, otherwise go to step 6.
6: If the mushroom has broad gills go to step 4, otherwise go to step 3.
5: If the mushroom has broad gills go to step 3, otherwise go to step 4.
4: If the mushroom has white spores go to step 2, otherwise go to step 1.
3: If the mushroom has white spores go to step 1, otherwise go to step 2.
2: Eat the mushroom.
1: Do not eat the mushroom.
./fungi -c with full-credit common subexpression elimination
Start on line 18
18: If the mushroom has no odor go to step 13, otherwise go to step 17.
17: If the mushroom has a club stalk go to step 14, otherwise go to step 16.
16: If the mushroom has an anise odor go to step 2, otherwise go to step 15.
15: If the mushroom has an almond odor go to step 2, otherwise go to step 1.
14: If the mushroom has a musty odor go to step 1, otherwise go to step 2.
13: If the mushroom has green spores go to step 1, otherwise go to step 12.
12: If the mushroom has a yellow cap go to step 1, otherwise go to step 11.
11: If the mushroom has a yellow stalk go to step 1, otherwise go to step 10.
10: If the mushroom has a conical cap shape go to step 1, otherwise go to step 9.
9: If the mushroom has a knobbed cap shape go to step 7, otherwise go to step 8.
8: If the mushroom has broad gills go to step 2, otherwise go to step 1.
7: If the mushroom has broad gills go to step 2, otherwise go to step 6.
6: If the mushroom has a white cap go to step 3, otherwise go to step 5.
5: If the mushroom has white spores go to step 4, otherwise go to step 2.
4: If the mushroom has a missing stalk go to step 1, otherwise go to step 2.
3: If the mushroom has a missing stalk go to step 2, otherwise go to step 1.
2: Eat the mushroom.
1: Do not eat the mushroom.