/*------------------------------------------------------*/ /* Induction of Decision Trees */ /*------------------------------------------------------*/ /* (C) 1994 Zdravko Markov */ /* Updated: Sping-2005 */ /*------------------------------------------------------*/ /* Example format: example(ID, Class, [A=V,...]). */ /* Use: */ /* Create a decision tree: ?- id3(Threshold). */ /* Print tree: ?- show. */ /* Print rules: ?- listing(if). */ /*------------------------------------------------------*/ /* Additional procedures for experimenting: */ /* ?- entropy(List_of_example_IDs, Entropy). */ /* ?- distr(List_of_example_IDs, [C1/N1, C2/N2,...]). */ /* (where Ni is the number of occurences of Ci) */ /* Get the set of attributes: ?- attr(L). */ /* Get the set of values for attr. A: ?- vals(A,L). */ /*------------------------------------------------------*/ /*------------------------------------------------------*/ ?- op(100,fx,if). ?- op(99,xfy,then). /*------------------------------------------------------*/ id3 :- id3(1). % for compatibility with old versions id3(Tr) :- retractall(node(_,_,_)), retractall(if _ then _), findall(N,example(N,_,_),E), example(_,_,L), !, get_attributes(L,A), idt(E,root,A,Tr), assert_rules, !. idt(E,Parent,_,Tr) :- length(E,Len), Len=