我想实现一个简单的随机森林回归来预测值。输入是具有多个功能的一些样本,标签是一个值。但是,我找不到有关随机森林回归问题的简单示例。因此,我看到的文件tensorflow,我发现:
可以训练和评估随机森林的估算器。例:
python
params = tf.contrib.tensor_forest.python.tensor_forest.ForestHParams(
num_classes=2, num_features=40, num_trees=10, max_nodes=1000)
# Estimator using the default graph builder.
estimator = TensorForestEstimator(params, model_dir=model_dir)
# Or estimator using TrainingLossForest as the graph builder.
estimator = TensorForestEstimator(
params, graph_builder_class=tensor_forest.TrainingLossForest,
model_dir=model_dir)
# Input builders
def input_fn_train: # returns x, y
...
def input_fn_eval: # returns x, y
...
estimator.fit(input_fn=input_fn_train)
estimator.evaluate(input_fn=input_fn_eval)
# Predict returns an iterable of dicts.
results = list(estimator.predict(x=x))
prob0 = results[0][eval_metrics.INFERENCE_PROB_NAME]
prediction0 = results[0][eval_metrics.INFERENCE_PRED_NAME]
Run Code Online (Sandbox Code Playgroud)
但是,当我按照示例进行操作时,出现了错误prob0 = results[0][eval_metrics.INFERENCE_PROB_NAME],该错误表明:
Example conversion: …Run Code Online (Sandbox Code Playgroud)