def average_impurity(self):
    'Constructs a TF graph for evaluating the average leaf impurity of a tree.\n\n    If in regression mode, this is the leaf variance. If in classification mode,\n    this is the gini impurity.\n\n    Returns:\n      The last op in the graph.\n    '
    children = array_ops.squeeze(array_ops.slice(self.variables.tree, [0, 0], [(- 1), 1]), squeeze_dims=[1])
    is_leaf = math_ops.equal(constants.LEAF_NODE, children)
    leaves = math_ops.to_int32(array_ops.squeeze(array_ops.where(is_leaf), squeeze_dims=[1]))
    counts = array_ops.gather(self.variables.node_sums, leaves)
    gini = self._weighted_gini(counts)

    def impurity():
        return gini

    def big():
        return (array_ops.ones_like(gini, dtype=dtypes.float32) * 10000000.0)
    return control_flow_ops.cond(math_ops.greater(array_ops.shape(leaves)[0], 0), impurity, big)
Constructs a TF graph for evaluating the average leaf impurity of a tree.

If in regression mode, this is the leaf variance. If in classification mode,
this is the gini impurity.

Returns:
  The last op in the graph.
def average_impurity(self):
    'Constructs a TF graph for evaluating the average leaf impurity of a tree.\n\n    If in regression mode, this is the leaf variance. If in classification mode,\n    this is the gini impurity.\n\n    Returns:\n      The last op in the graph.\n    '
    children = array_ops.squeeze(array_ops.slice(self.variables.tree, [0, 0], [(- 1), 1]), squeeze_dims=[1])
    is_leaf = math_ops.equal(constants.LEAF_NODE, children)
    leaves = math_ops.to_int32(array_ops.squeeze(array_ops.where(is_leaf), squeeze_dims=[1]))
    counts = array_ops.gather(self.variables.node_sums, leaves)
    gini = self._weighted_gini(counts)

    def impurity():
        return gini

    def big():
        return (array_ops.ones_like(gini, dtype=dtypes.float32) * 10000000.0)
    return control_flow_ops.cond(math_ops.greater(array_ops.shape(leaves)[0], 0), impurity, big)