July 2017
Intermediate to advanced
382 pages
9h 13m
English
Building the decision tree with OpenCV works in much the same way as in Chapter 3, First Steps in Supervised Learning. Recall that all the machine learning functions reside in OpenCV 3.1's ml module. We can create an empty decision tree using the following code:
In [16]: import cv2... dtree = cv2.ml.dtree_create()
In order to train the decision tree on the training data, we use the method train:
In [17]: dtree.train(X_train, cv2.ml.ROW_SAMPLE, y_train)
Here we have to specify whether the data samples in X_train occupy the rows (using cv2.ml.ROW_SAMPLE) or the columns (cv2.ml.COL_SAMPLE).
Then we can predict the labels of the new data points with predict:
In [18]: y_pred = dtree.predict(X_test)
If we want to know ...
Read now
Unlock full access