aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/boosted_trees/estimator_batch
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-05-25 16:07:25 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-05-25 16:10:20 -0700
commitf69f4f0592accd26c0f49d18e360cc4cdb2ce5b3 (patch)
tree062a48e22e30742ec1f0a1f63f55fb10f14e322a /tensorflow/contrib/boosted_trees/estimator_batch
parent5430f37a9aaf463ffba13e47121fc9b6a5834cd2 (diff)
Automated g4 rollback of changelist 198087342
PiperOrigin-RevId: 198117552
Diffstat (limited to 'tensorflow/contrib/boosted_trees/estimator_batch')
-rw-r--r--tensorflow/contrib/boosted_trees/estimator_batch/estimator.py38
-rw-r--r--tensorflow/contrib/boosted_trees/estimator_batch/estimator_test.py33
-rw-r--r--tensorflow/contrib/boosted_trees/estimator_batch/model.py8
3 files changed, 9 insertions, 70 deletions
diff --git a/tensorflow/contrib/boosted_trees/estimator_batch/estimator.py b/tensorflow/contrib/boosted_trees/estimator_batch/estimator.py
index c8d401bfa6..89d0d611d2 100644
--- a/tensorflow/contrib/boosted_trees/estimator_batch/estimator.py
+++ b/tensorflow/contrib/boosted_trees/estimator_batch/estimator.py
@@ -41,8 +41,7 @@ class GradientBoostedDecisionTreeClassifier(estimator.Estimator):
feature_engineering_fn=None,
logits_modifier_function=None,
center_bias=True,
- use_core_libs=False,
- output_leaf_index=False):
+ use_core_libs=False):
"""Initializes a GradientBoostedDecisionTreeClassifier estimator instance.
Args:
@@ -67,14 +66,6 @@ class GradientBoostedDecisionTreeClassifier(estimator.Estimator):
the bias.
use_core_libs: Whether feature columns and loss are from the core (as
opposed to contrib) version of tensorflow.
- output_leaf_index: whether to output leaf indices along with predictions
- during inference. The leaf node indexes are available in predictions
- dict by the key 'leaf_index'. For example,
- result_dict = classifier.predict(...)
- for example_prediction_result in result_dict:
- # access leaf index list by example_prediction_result["leaf_index"]
- # which contains one leaf index per tree
-
Raises:
ValueError: If learner_config is not valid.
"""
@@ -83,9 +74,7 @@ class GradientBoostedDecisionTreeClassifier(estimator.Estimator):
# supports second order derivative.
def loss_fn(labels, logits, weights=None):
result = losses.per_example_maxent_loss(
- labels=labels,
- logits=logits,
- weights=weights,
+ labels=labels, logits=logits, weights=weights,
num_classes=n_classes)
return math_ops.reduce_mean(result[0])
else:
@@ -113,7 +102,6 @@ class GradientBoostedDecisionTreeClassifier(estimator.Estimator):
'center_bias': center_bias,
'logits_modifier_function': logits_modifier_function,
'use_core_libs': use_core_libs,
- 'output_leaf_index': output_leaf_index,
},
model_dir=model_dir,
config=config,
@@ -136,8 +124,7 @@ class GradientBoostedDecisionTreeRegressor(estimator.Estimator):
feature_engineering_fn=None,
logits_modifier_function=None,
center_bias=True,
- use_core_libs=False,
- output_leaf_index=False):
+ use_core_libs=False):
"""Initializes a GradientBoostedDecisionTreeRegressor estimator instance.
Args:
@@ -164,13 +151,6 @@ class GradientBoostedDecisionTreeRegressor(estimator.Estimator):
the bias.
use_core_libs: Whether feature columns and loss are from the core (as
opposed to contrib) version of tensorflow.
- output_leaf_index: whether to output leaf indices along with predictions
- during inference. The leaf node indexes are available in predictions
- dict by the key 'leaf_index'. For example,
- result_dict = classifier.predict(...)
- for example_prediction_result in result_dict:
- # access leaf index list by example_prediction_result["leaf_index"]
- # which contains one leaf index per tree
"""
head = head_lib.regression_head(
label_name=label_name,
@@ -193,7 +173,6 @@ class GradientBoostedDecisionTreeRegressor(estimator.Estimator):
'logits_modifier_function': logits_modifier_function,
'center_bias': center_bias,
'use_core_libs': use_core_libs,
- 'output_leaf_index': False,
},
model_dir=model_dir,
config=config,
@@ -218,8 +197,7 @@ class GradientBoostedDecisionTreeEstimator(estimator.Estimator):
feature_engineering_fn=None,
logits_modifier_function=None,
center_bias=True,
- use_core_libs=False,
- output_leaf_index=False):
+ use_core_libs=False):
"""Initializes a GradientBoostedDecisionTreeEstimator estimator instance.
Args:
@@ -242,13 +220,6 @@ class GradientBoostedDecisionTreeEstimator(estimator.Estimator):
the bias.
use_core_libs: Whether feature columns and loss are from the core (as
opposed to contrib) version of tensorflow.
- output_leaf_index: whether to output leaf indices along with predictions
- during inference. The leaf node indexes are available in predictions
- dict by the key 'leaf_index'. For example,
- result_dict = classifier.predict(...)
- for example_prediction_result in result_dict:
- # access leaf index list by example_prediction_result["leaf_index"]
- # which contains one leaf index per tree
"""
super(GradientBoostedDecisionTreeEstimator, self).__init__(
model_fn=model.model_builder,
@@ -262,7 +233,6 @@ class GradientBoostedDecisionTreeEstimator(estimator.Estimator):
'logits_modifier_function': logits_modifier_function,
'center_bias': center_bias,
'use_core_libs': use_core_libs,
- 'output_leaf_index': False,
},
model_dir=model_dir,
config=config,
diff --git a/tensorflow/contrib/boosted_trees/estimator_batch/estimator_test.py b/tensorflow/contrib/boosted_trees/estimator_batch/estimator_test.py
index fe91e5293f..0d58317bd5 100644
--- a/tensorflow/contrib/boosted_trees/estimator_batch/estimator_test.py
+++ b/tensorflow/contrib/boosted_trees/estimator_batch/estimator_test.py
@@ -62,34 +62,12 @@ class BoostedTreeEstimatorTest(test_util.TensorFlowTestCase):
examples_per_layer=3,
model_dir=model_dir,
config=config,
- feature_columns=[contrib_feature_column.real_valued_column("x")],
- output_leaf_index=False)
+ feature_columns=[contrib_feature_column.real_valued_column("x")])
classifier.fit(input_fn=_train_input_fn, steps=15)
classifier.evaluate(input_fn=_eval_input_fn, steps=1)
classifier.export(self._export_dir_base)
- def testThatLeafIndexIsInPredictions(self):
- learner_config = learner_pb2.LearnerConfig()
- learner_config.num_classes = 2
- learner_config.constraints.max_tree_depth = 1
- model_dir = tempfile.mkdtemp()
- config = run_config.RunConfig()
-
- classifier = estimator.GradientBoostedDecisionTreeClassifier(
- learner_config=learner_config,
- num_trees=1,
- examples_per_layer=3,
- model_dir=model_dir,
- config=config,
- feature_columns=[contrib_feature_column.real_valued_column("x")],
- output_leaf_index=True)
-
- classifier.fit(input_fn=_train_input_fn, steps=15)
- result_dict = classifier.predict(input_fn=_eval_input_fn)
- for prediction_item in result_dict:
- self.assertTrue("leaf_index" in prediction_item)
-
def testFitAndEvaluateDontThrowExceptionWithCoreForEstimator(self):
learner_config = learner_pb2.LearnerConfig()
learner_config.num_classes = 2
@@ -109,8 +87,7 @@ class BoostedTreeEstimatorTest(test_util.TensorFlowTestCase):
model_dir=model_dir,
config=config,
feature_columns=[core_feature_column.numeric_column("x")],
- use_core_libs=True,
- output_leaf_index=False)
+ use_core_libs=True)
model.fit(input_fn=_train_input_fn, steps=15)
model.evaluate(input_fn=_eval_input_fn, steps=1)
@@ -130,8 +107,7 @@ class BoostedTreeEstimatorTest(test_util.TensorFlowTestCase):
model_dir=model_dir,
config=config,
feature_columns=[core_feature_column.numeric_column("x")],
- use_core_libs=True,
- output_leaf_index=False)
+ use_core_libs=True)
classifier.fit(input_fn=_train_input_fn, steps=15)
classifier.evaluate(input_fn=_eval_input_fn, steps=1)
@@ -151,8 +127,7 @@ class BoostedTreeEstimatorTest(test_util.TensorFlowTestCase):
model_dir=model_dir,
config=config,
feature_columns=[core_feature_column.numeric_column("x")],
- use_core_libs=True,
- output_leaf_index=False)
+ use_core_libs=True)
regressor.fit(input_fn=_train_input_fn, steps=15)
regressor.evaluate(input_fn=_eval_input_fn, steps=1)
diff --git a/tensorflow/contrib/boosted_trees/estimator_batch/model.py b/tensorflow/contrib/boosted_trees/estimator_batch/model.py
index 1ee8911989..15ab6d8145 100644
--- a/tensorflow/contrib/boosted_trees/estimator_batch/model.py
+++ b/tensorflow/contrib/boosted_trees/estimator_batch/model.py
@@ -63,8 +63,6 @@ def model_builder(features, labels, mode, params, config):
num_trees = params["num_trees"]
use_core_libs = params["use_core_libs"]
logits_modifier_function = params["logits_modifier_function"]
- output_leaf_index = params["output_leaf_index"]
-
if features is None:
raise ValueError("At least one feature must be specified.")
@@ -98,8 +96,7 @@ def model_builder(features, labels, mode, params, config):
feature_columns=feature_columns,
logits_dimension=head.logits_dimension,
features=training_features,
- use_core_columns=use_core_libs,
- output_leaf_index=output_leaf_index)
+ use_core_columns=use_core_libs)
with ops.name_scope("gbdt", "gbdt_optimizer"):
predictions_dict = gbdt_model.predict(mode)
logits = predictions_dict["predictions"]
@@ -130,9 +127,6 @@ def model_builder(features, labels, mode, params, config):
labels=labels,
train_op_fn=_train_op_fn,
logits=logits)
- if output_leaf_index and gbdt_batch.LEAF_INDEX in predictions_dict:
- model_fn_ops.predictions[gbdt_batch.LEAF_INDEX] = predictions_dict[
- gbdt_batch.LEAF_INDEX]
if num_trees:
if center_bias:
num_trees += 1