資源簡介
官方例子,深度學習專用,機器學習專用,代碼簡單,一看就會(tensorflow random forest demo)
代碼片段和文件信息
“““?Random?Forest.
Implement?Random?Forest?algorithm?with?TensorFlow?and?apply?it?to?classify?
handwritten?digit?images.?This?example?is?using?the?MNIST?database?of?
handwritten?digits?as?training?samples?(http://yann.lecun.com/exdb/mnist/).
Author:?Aymeric?Damien
Project:?https://github.com/aymericdamien/TensorFlow-Examples/
“““
from?__future__?import?print_function
import?tensorflow?as?tf
from?tensorflow.contrib.tensor_forest.python?import?tensor_forest
from?tensorflow.python.ops?import?resources
#?Ignore?all?GPUs?tf?random?forest?does?not?benefit?from?it.
import?os
os.environ[“CUDA_VISIBLE_DEVICES“]?=?““
#?Import?MNIST?data
from?tensorflow.examples.tutorials.mnist?import?input_data
mnist?=?input_data.read_data_sets(“/tmp/data/“?one_hot=False)
#?Parameters
num_steps?=?500?#?Total?steps?to?train
batch_size?=?1024?#?The?number?of?samples?per?batch
num_classes?=?10?#?The?10?digits
num_features?=?784?#?Each?image?is?28x28?pixels
num_trees?=?10
max_nodes?=?1000
#?Input?and?Target?data
X?=?tf.placeholder(tf.float32?shape=[None?num_features])
#?For?random?forest?labels?must?be?integers?(the?class?id)
Y?=?tf.placeholder(tf.int32?shape=[None])
#?Random?Forest?Parameters
hparams?=?tensor_forest.ForestHParams(num_classes=num_classes
??????????????????????????????????????num_features=num_features
??????????????????????????????????????num_trees=num
評論
共有 條評論