Have a question? Connect with the community at the TensorFlow Forum Visit Forum

Module: tfdf.builder

Model builder.

The model builder let the user create models by hand i.e. by defining the tree structure manually.

The available builders are:

  • RandomForestBuilder
  • CARTBuilder
  • GradientBoostedTreeBuilder

Usage:


# Create a binary classification CART model.
builder = builder_lib.CARTBuilder(
  path="/path/to/model",
  objective=py_tree.objective.ClassificationObjective(
  label="color", classes=["red", "blue"]))

# Create the tree
#  f1>=1.5
#    ├─(pos)─ [0.1, 0.9]
#    └─(neg)─ [0.8, 0.2]
#
# The component of the trees (e.g. `NonLeafNode`, `Tree`) are defined in
# `tfdf.py_tree.`.
#
builder.add_tree(
    Tree(
        NonLeafNode(
            condition=NumericalHigherThanCondition(
                feature=SimpleColumnSpec(
                    name="f1", type=py_tree.dataspec.ColumnType.NUMERICAL),
                threshold=1.5,
                missing_evaluation=False),
            pos_child=LeafNode(
                value=ProbabilityValue(probability=[0.1, 0.9])),
            neg_child=LeafNode(
                value=ProbabilityValue(probability=[0.8, 0.2])))))

builder.close()

# Load and use the model
model = tf.keras.models.load_model("/path/to/model")
predictions = model.predict(...)

Classes

class AbstractBuilder: Generic model builder.

class AbstractDecisionForestBuilder: Generic decision forest model builder.

class CARTBuilder: CART model builder.

class Enum: Generic enumeration.

class GradientBoostedTreeBuilder: Gradient Boosted Tree model builder.

class ModelFormat: Model formats on disk.

class RandomForestBuilder: Random Forest model builder.

ColumnType Instance of google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper
Task Instance of google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper