Decision Trees
A simple implementation of the Decision Tree learning algorithm as described in
chapter 18 of Artificial Intelligence: A Modern Approach; by Stuart Russell and Peter Norvig. What was implemented:
What was not implemented:
Remarks
Sample use
I've left parts of the code out here, to make it more readable. CDTModel DecisionTreeModel(ATTRIBUTE_COUNT); CDTDecisionTree *DecisionTree; .... more variables .... // first add the attributes Attribute = new CDTAttribute("Is there an alternative restaurant nearby?"); Attribute->AddValue(YES, "Yes"); Attribute->AddValue(NO, "No"); DecisionTreeModel.SetAttribute(0, Attribute); Attribute = new CDTAttribute("Does the restaurant have a comfortable bar?"); Attribute->AddValue(YES, "Yes"); Attribute->AddValue(NO, "No"); DecisionTreeModel.SetAttribute(1, Attribute); .... more attributes ... // fill the model with examples for (int Index=0; Index < EXAMPLE_COUNT; Index++) { // create object from attribute values Object = CreateObject(ObjectValues[Index]); // let model manage object DecisionTreeModel.AddObject(Object); // add example to decision tree DecisionTreeModel.AddExample(Object, WillWait[Index]); } // create sample object SampleObject = CreateObject(SampleObjectValues); // learn the decision tree DecisionTree = DecisionTreeModel.CreateDecisionTree(); // ask the decision tree to decide if we should wait in a certain situation DecisionValue = DecisionTree->MakeDecision(*SampleObject); // print the decision tree printf("%s\n", DecisionTree->ToString().GetBuffer()); // remove data delete DecisionTree; delete SampleObject; Links
|