July 2017
Intermediate to advanced
382 pages
9h 13m
English
Although we have so far focused on using decision trees in classification tasks, you can also use them for regression. But you will need to use scikit-learn again, as OpenCV does not provide this flexibility. We therefore only briefly review its functionality here.
Let's say we wanted to use a decision tree to fit a sin wave. To make things interesting, we will also add some noise to the data points using NumPy's random number generator:
In [1]: import numpy as np... rng = np.random.RandomState(42)
We then create 100 x values between 0 and 5, and calculate the corresponding sin values:
In [2]: X = np.sort(5 * rng.rand(100, 1), axis=0)... y = np.sin(X).ravel()
We then add noise to every other data point ...
Read now
Unlock full access