New! Use Simple ML for Sheets to apply machine learning to the data in your Google Sheets
Read More
Module: tfdf.tuner
Stay organized with collections
Save and categorize content based on your preferences.
Specification of the parameters of a tuner.
The "tuner" is a meta-learning algorithm that find the optimal hyperparameter
values of a base learner. "Tuner" is the TF-DF name for the YDF automatic
Hyperparameter optimizer V2. For example, a tuner can find the hyper-parameters
that maximize the accuracy of a GradientBoostedTreesModel model.
Usage example:
# Imports
import tensorflow_decision_forests as tfdf
# Load a dataset into a Pandas Dataframe.
dataset_df = pd.read_csv("/tmp/penguins.csv")
# Convert the Pandas dataframe to a tf dataset
tf_dataset = tfdf.keras.pd_dataframe_to_tf_dataset(dataset_df,label="species")
# Configure the tuner.
tuner = tfdf.tuner.RandomSearch(num_trials=20)
tuner.choice("num_candidate_attributes_ratio", [1.0, 0.8, 0.6])
tuner.choice("use_hessian_gain", [True, False])
local_search_space = tuner.choice("growing_strategy", ["LOCAL"])
local_search_space.choice("max_depth", [4, 5, 6, 7])
global_search_space = tuner.choice(
"growing_strategy", ["BEST_FIRST_GLOBAL"], merge=True)
global_search_space.choice("max_num_nodes", [16, 32, 64, 128])
# Configure and train the model.
model = tfdf.keras.GradientBoostedTreesModel(num_trees=50, tuner=tuner)
model.fit(tf_dataset)
Classes
class HPOptProto
: A ProtocolMessage
class RandomSearch
: Tuner using random hyperparameter values.
class SearchSpace
: Set of hyperparameter and their respective possible values.
class TrainConfig
: A ProtocolMessage
class Tuner
: Abstract tuner class.
Other Members |
annotations
|
Instance of __future__._Feature
|
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 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# Module: tfdf.tuner\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/decision-forests/blob/main/tensorflow_decision_forests/component/tuner/tuner.py) |\n\nSpecification of the parameters of a tuner.\n\nThe \"tuner\" is a meta-learning algorithm that find the optimal hyperparameter\nvalues of a base learner. \"Tuner\" is the TF-DF name for the YDF automatic\nHyperparameter optimizer V2. For example, a tuner can find the hyper-parameters\nthat maximize the accuracy of a GradientBoostedTreesModel model.\n\n#### Usage example:\n\n # Imports\n import tensorflow_decision_forests as tfdf\n\n # Load a dataset into a Pandas Dataframe.\n dataset_df = pd.read_csv(\"/tmp/penguins.csv\")\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 # Configure the tuner.\n tuner = tfdf.tuner.RandomSearch(num_trials=20)\n tuner.choice(\"num_candidate_attributes_ratio\", [1.0, 0.8, 0.6])\n tuner.choice(\"use_hessian_gain\", [True, False])\n\n local_search_space = tuner.choice(\"growing_strategy\", [\"LOCAL\"])\n local_search_space.choice(\"max_depth\", [4, 5, 6, 7])\n\n global_search_space = tuner.choice(\n \"growing_strategy\", [\"BEST_FIRST_GLOBAL\"], merge=True)\n global_search_space.choice(\"max_num_nodes\", [16, 32, 64, 128])\n\n # Configure and train the model.\n model = tfdf.keras.GradientBoostedTreesModel(num_trees=50, tuner=tuner)\n model.fit(tf_dataset)\n\nClasses\n-------\n\n[`class HPOptProto`](../tfdf/tuner/HPOptProto): A ProtocolMessage\n\n[`class RandomSearch`](../tfdf/tuner/RandomSearch): Tuner using random hyperparameter values.\n\n[`class SearchSpace`](../tfdf/tuner/SearchSpace): Set of hyperparameter and their respective possible values.\n\n[`class TrainConfig`](../tfdf/keras/core/YggdrasilTrainingConfig): A ProtocolMessage\n\n[`class Tuner`](../tfdf/tuner/Tuner): Abstract tuner class.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Other Members ------------- ||\n|-------------|-----------------------------------|\n| annotations | Instance of `__future__._Feature` |\n\n\u003cbr /\u003e"]]