| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.98.0/docs/handbook/_sources/libraries/c45.rst.txt |
.. _library_c45:
c45This library implements the C4.5 decision tree learning algorithm. C4.5 is an extension of the ID3 algorithm that uses information gain ratio instead of information gain for attribute selection, which avoids bias towards attributes with many values (see below for implementation details).
The library implements the classifier_protocol defined in the
classifier_protocols library. It provides predicates for learning a
decision tree from a dataset, optionally prune it, using it to make
predictions, and exporting it as a list of predicate clauses or to a
file.
Datasets are represented as objects implementing the
dataset_protocol protocol from the classifier_protocols library.
See test_files directory for examples.
Open the `../../apis/library_index.html#c45 <../../apis/library_index.html#c45>`__ link in a web browser.
To load all entities in this library, load the loader.lgt file:
::
| ?- logtalk_load(c45(loader)).
To test this library predicates, load the tester.lgt file:
::
| ?- logtalk_load(c45(tester)).
To learn a decision tree from a dataset:
::
| ?- c45::learn(play_tennis, Tree).
To prune a learned tree with the default parameters (confidence factor 0.25, minimum instances per leaf 2):
::
| ?- c45::learn(breast_cancer, Tree),
c45::prune(breast_cancer, Tree, PrunedTree).
To prune a learned tree with both custom confidence factor and minimum instances per leaf:
::
| ?- c45::learn(breast_cancer, Tree),
c45::prune(breast_cancer, Tree, 0.1, 3, PrunedTree).
To export the tree as a list of predicate clauses:
::
| ?- c45::learn(play_tennis, Tree),
c45::tree_to_clauses(play_tennis, Tree, classify, Clauses).
To export the tree to a file:
::
| ?- c45::learn(play_tennis, Tree),
c45::tree_to_file(play_tennis, Tree, classify, 'tree.pl').
To print the tree to the current output:
::
| ?- c45::learn(play_tennis, Tree),
c45::print_tree(Tree).
To predict the class for a new instance (as a list of attribute-value pairs):
::
| ?- c45::learn(play_tennis, Tree),
c45::predict(Tree, [outlook-sunny, temperature-hot, humidity-high, wind-weak], Class).