Update hoeffding_tree authored by Dean Samuel Schmitz's avatar Dean Samuel Schmitz
......@@ -2,17 +2,25 @@
An implementation of Hoeffding trees, a form of streaming decision tree for classification. Given labeled data, a Hoeffding tree can be used for predicting the classifications of new points.
```prolog
:- use_module('path/to/.../src/methods/adaboost/adaboost.pl').
%% usage example
adaboost_initModelWithTraining([5.1,3.5,1.4, 4.9,3.0,1.4, 4.7,3.2,1.3, 4.6,3.1,1.5], 3, [0,0,1,0], 2, perceptron, 50, 0.0001),
adaboost_classify([3,2,0, 5,1,4, 0,0,4, 3,3,5, 0,5,5, 2,5,5], 3, PredictionList, ProbabilitiesList, _).
```
# Available Predicates
* [initAndBuildModel/14](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/hoeffding_tree#initandbuildmodel14)
* [classify/7](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/hoeffding_tree#classify7)
* [train/6](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/hoeffding_tree#train6)
* [hoeffding_tree_initAndBuildModel/12](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/hoeffding_tree#hoeffding_tree_initandbuildmodel12)
* [hoeffding_tree_classify/4](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/hoeffding_tree#hoeffding_tree_classify4)
* [hoeffding_tree_train/4](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/hoeffding_tree#hoeffding_tree_train4)
---
[links/resources](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/hoeffding_tree#connected-linksresources)
## **_initAndBuildModel/14_**
## **_hoeffding_tree_initAndBuildModel/12_**
Construct the Hoeffding tree with the given parameters and given training data.
......@@ -20,12 +28,23 @@ The tree may be trained either in batch mode (which looks at all points before s
```prolog
%% part of the predicate definition
initAndBuildModel( +string,
hoeffding_tree_initAndBuildModel(TreeType, DataList, DataRows, LabelsList, NumClasses, BatchTraining, SuccessProbability, MaxSamples, CheckInterval, MinSamples, Bins, ObservationsBeforeBinning) :-
NumClasses >= 0,
SuccessProbability >= 0,
SuccessProbability =< 1,
MaxSamples >= 0,
CheckInterval > 0,
MinSamples >= 0,
Bins >= 0,
ObservationsBeforeBinning >= 0,
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrownum, X)),
convert_list_to_float_array(LabelsList, array(Ysize, Y)),
initAndBuildModelI(TreeType, X, Xsize, Xrownum, Y, Ysize, NumClasses, BatchTraining, SuccessProbability, MaxSamples, CheckInterval, MinSamples, Bins, ObservationsBeforeBinning).
foreign(initAndBuildModel, c, initAndBuildModelI( +string,
+pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer,
+integer,
+float32, +integer, +integer, +integer, +integer, +integer).
+integer, +integer, +float32, +integer, +integer, +integer, +integer, +integer)).
```
### Parameters
......@@ -45,17 +64,24 @@ initAndBuildModel( +string,
---
## **_classify/7_**
## **_hoeffding_tree_classify/4_**
Classify the given points, using this node and the entire (sub)tree beneath it.
The predicted labels for each point are returned, as well as an estimate of the probability that the prediction is correct for each point. This estimate is simply the **MajorityProbability** for the leaf that each point bins to.
```prolog
%% part of the predicate definition
classify( +pointer(float_array), +integer, +integer,
%% predicate definition
hoeffding_tree_classify(TestList, TestRows, PredicList, ProbsList) :-
convert_list_to_float_array(TestList, TestRows, array(Xsize, Xrownum, X)),
classifyI(X, Xsize, Xrownum, Y, Ysize, Z, Zsize),
convert_float_array_to_list(Y, Ysize, PredicList),
convert_float_array_to_list(Z, Zsize, ProbsList).
%% foreign c++ predicate definition
foreign(classify, c, classifyI( +pointer(float_array), +integer, +integer,
-pointer(float_array), -integer,
-pointer(float_array), -integer).
-pointer(float_array), -integer)).
```
### Parameters
......@@ -67,17 +93,23 @@ classify( +pointer(float_array), +integer, +integer,
---
## **_train/6_**
## **_hoeffding_tree_train/4_**
Train in streaming mode on the given dataset.
This takes one pass. Be sure that initAndBuildModel/14 has been called first!
This takes one pass. Be sure that hoeffding_tree_initAndBuildModel/12 has been called first!
```prolog
%% part of the predicate definition
train( +pointer(float_array), +integer, +integer,
%% predicate definition
hoeffding_tree_train(DataList, DataRows, LabelsList, BatchTraining) :-
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrownum, X)),
convert_list_to_float_array(LabelsList, array(Ysize, Y)),
trainI(X, Xsize, Xrownum, Y, Ysize, BatchTraining).
%% foreign c++ predicate definition
foreign(train, c, trainI( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer).
+integer)).
```
### Parameters
......@@ -93,8 +125,8 @@ train( +pointer(float_array), +integer, +integer,
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
* [**MLpack::hoeffding_tree_C++\_documentation**](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1tree_1_1HoeffdingTree.html)
* [**MLpack::hoeffding_tree_Python_documentation**](https://www.mlpack.org/doc/stable/python_documentation.html#hoeffding_tree)
* [**MLpack::hoeffding_tree_C++\_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/doxygen/classmlpack_1_1tree_1_1HoeffdingTree.html)
* [**MLpack::hoeffding_tree_Python_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/python_documentation.html#hoeffding_tree)
added some of the links from the python documentation
......
......