This is a bonus section where we implement a random forest with TensorFlow. Let's take a look at the following steps and see how it is done:
- First, we import the modules we need, as follows:
>>> import tensorflow as tf>>> from tensorflow.contrib.tensor_forest.python import tensor_forest>>> from tensorflow.python.ops import resources
- Specify the parameters of the model, including 20 iterations during the training process, 10 trees in total, and 30000 maximal splitting nodes:
>>> n_iter = 20>>> n_classes = 2>>> n_features = int(X_train_enc.toarray().shape[1])>>> n_trees = 10>>> max_nodes = 30000
- Next, we create placeholders and build the TensorFlow graph:
>>> x = tf.placeholder(tf.float32, shape=[None, ...