New! Use Simple ML for Sheets to apply machine learning to the data in your Google Sheets
Read More
Module: tfdf
Stay organized with collections
Save and categorize content based on your preferences.
User entry point for the TensorFlow Decision Forest API.
Basic usage:
# Imports
import tensorflow_decision_forests as tfdf
import pandas as pd
from wurlitzer import sys_pipes
# Load a dataset into a Pandas Dataframe.
dataset_df = pd.read_csv("/tmp/penguins.csv")
# Display the first 3 examples.
dataset_df.head(3)
# Convert the Pandas dataframe to a tf dataset
tf_dataset = tfdf.keras.pd_dataframe_to_tf_dataset(dataset_df,label="species")
model = tfdf.keras.RandomForestModel()
with sys_pipes():
model.fit(tf_dataset)
# Note: The `sys_pipes` part is to display logs during training.
# Evaluate model.
model.compile(metrics=["accuracy"])
model.evaluate(...test_dataset...)
# Save model.
model.save("/tmp/my_saved_model")
# ...
# Load a model: it loads as a generic keras model.
loaded_model = tf_keras.models.load_model("/tmp/my_saved_model")
Modules
builder
module: Model builder.
check_version
module: Check that version of TensorFlow is compatible with TF-DF.
inspector
module: Model inspector.
keras
module: Decision Forest in a Keras Model.
model_plotter
module: Plotting of decision forest models.
py_tree
module: Decision trees stored as python objects.
tuner
module: Specification of the parameters of a tuner.
Other Members |
version
|
'1.12.0'
|
compatible_tf_versions
|
['2.19.0']
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-03-14 UTC.
[null,null,["Last updated 2025-03-14 UTC."],[],[],null,["# Module: tfdf\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/decision-forests/blob/main/tensorflow_decision_forests/__init__.py) |\n\nUser entry point for the TensorFlow Decision Forest API.\n\n#### Basic usage:\n\n # Imports\n import tensorflow_decision_forests as tfdf\n import pandas as pd\n from wurlitzer import sys_pipes\n\n # Load a dataset into a Pandas Dataframe.\n dataset_df = pd.read_csv(\"/tmp/penguins.csv\")\n\n # Display the first 3 examples.\n dataset_df.head(3)\n\n # Convert the Pandas dataframe to a tf dataset\n tf_dataset = tfdf.keras.pd_dataframe_to_tf_dataset(dataset_df,label=\"species\")\n\n model = tfdf.keras.RandomForestModel()\n with sys_pipes():\n model.fit(tf_dataset)\n # Note: The `sys_pipes` part is to display logs during training.\n\n # Evaluate model.\n model.compile(metrics=[\"accuracy\"])\n model.evaluate(...test_dataset...)\n\n # Save model.\n model.save(\"/tmp/my_saved_model\")\n\n # ...\n\n # Load a model: it loads as a generic keras model.\n loaded_model = tf_keras.models.load_model(\"/tmp/my_saved_model\")\n\nModules\n-------\n\n[`builder`](./tfdf/builder) module: Model builder.\n\n[`check_version`](./tfdf/check_version) module: Check that version of TensorFlow is compatible with TF-DF.\n\n[`inspector`](./tfdf/inspector) module: Model inspector.\n\n[`keras`](./tfdf/keras) module: Decision Forest in a Keras Model.\n\n[`model_plotter`](./tfdf/model_plotter) module: Plotting of decision forest models.\n\n[`py_tree`](./tfdf/py_tree) module: Decision trees stored as python objects.\n\n[`tuner`](./tfdf/tuner) module: Specification of the parameters of a tuner.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Other Members ------------- ||\n|------------------------|--------------|\n| **version** | `'1.12.0'` |\n| compatible_tf_versions | `['2.19.0']` |\n\n\u003cbr /\u003e"]]