在学习Tensorflow中的机器学习Estimator中的随机森林算法时发现,最新的版本(v1.0.1)中对随机深蓝的分类器的位置进行了改变。
之前的版本使用的语句为:
classifier = tf.contrib.learn.TensorForestEstimator(hparams)
在新的版本中必然会提示没有这个模块,查看官方文档说明,是将随机森林的Estimator模块,移到了contrib/tensor_forest下,参考(http://m.suneasecloud.com:8101/news/show_4473.html),那么在具体使用中如何实现呢,很简单:
hparams = tf.contrib.tensor_forest.python.tensor_forest.ForestHParams(num_trees=3,\
max_nodes=100,\
num_classes=3,\
num_features=4)
classifier = tf.contrib.tensor_forest.client.random_forest.TensorForestEstimator(hparams)
以上hparams时随机森林的参数设置,例如多少棵树,节点数目的上限,特征和类别的数目。
classifier就是应该使用的代码
参考:https://examples.gitly.io/tensorflow/blob/58067591b6266c49a07881d4c7e984d92bec9496/tensorflow/contrib/learn/python/learn/estimators/__init__.py?raw=1