September 2019
Intermediate to advanced
420 pages
10h 29m
English
We continue to follow our best practice to split the data into training and test sets:
In [8]: from sklearn.model_selection import train_test_split... X_train, X_test, y_train, y_test = train_test_split(... X, y, random_state=21... )
Then, we are ready to apply a random forest to the data:
In [9]: import cv2... rtree = cv2.ml.RTrees_create()
Here, we want to create an ensemble with 50 decision trees:
In [10]: n_trees = 50... eps = 0.01... criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,... n_trees, eps)... rtree.setTermCriteria(criteria)
Because we have a large number of categories (that is, 40), we want to make sure the random forest is set up to handle them accordingly:
In [10]: rtree.setMaxCategories(len(np.unique(y))) ...
Read now
Unlock full access