Registry / ai-ml / ydf
library0.16.1pypypiunverified

YDF (short for Yggdrasil Decision Forests) is a library for training, serving, evaluating, and analyzing decision forest models such as Random Forest and Gradient Boosted Trees. It acts as a lightweight, efficient wrapper around the C++ Yggdrasil Decision Forests library. YDF is the official successor to TensorFlow Decision Forests (TF-DF) and is recommended for new projects due to its superior performance and features. It is actively developed with frequent releases.

pip install ydf -U
INSTALL
IMPORT
SIG · YDF
Y
ydf
ai-mlpythonv0.16.1
Install
5.0s avg
Import
661ms
Disk
135MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.16.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 5.0s · import 0.661s · 133MB
135MB installed
● package 135MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ydf
import ydf
Primary import for all YDF functionalities.
GradientBoostedTreesLearner
import ydf model = ydf.GradientBoostedTreesLearner(...)
from ydf.learner import GradientBoostedTreesLearner
Most common classes like Learners and Models are exposed directly under the top-level 'ydf' namespace for simplicity.

This quickstart demonstrates how to install YDF, import the library, load a sample dataset using Pandas, train a Gradient Boosted Trees model, evaluate its performance, make predictions, and save/load the trained model. It uses the 'Adult' dataset for a binary classification task.

import ydf import pandas as pd import os # Load dataset with Pandas ds_path = "https://raw.githubusercontent.com/google/yggdrasil-decision-forests/main/yggdrasil_decision_forests/test_data/dataset/" try: train_ds = pd.read_csv(f"{ds_path}adult_train.csv") test_ds = pd.read_csv(f"{ds_path}adult_test.csv") except Exception as e: print(f"Could not load datasets: {e}. Ensure internet connection or provide local paths.") exit() # Train a Gradient Boosted Trees model # 'label' is the target column for prediction. # verbose=0 to suppress training logs for cleaner output, default is 1. model = ydf.GradientBoostedTreesLearner(label="income", verbose=0).train(train_ds) # Evaluate the model print("Model Evaluation:") print(model.evaluate(test_ds)) # Generate predictions predictions = model.predict(test_ds) print("\nFirst 5 predictions:") print(predictions.head()) # Save and Load the model model_path = "/tmp/my_ydf_model" model.save(model_path) loaded_model = ydf.load_model(model_path) print(f"\nModel saved to '{model_path}' and reloaded successfully.")
Debug
Known issues
breakingThe method `model.to_tensorflow_saved_model(mode="keras")` is strongly discouraged and will be removed in a future version. Exporting YDF models to TensorFlow SavedModel now primarily uses the separate `ydf-tf` package.
fix
Install `ydf-tf` (`pip install ydf-tf`) and use the recommended export methods provided by `ydf-tf` if TensorFlow SavedModel export is necessary.
affects: 0.15.0+
breakingSupport for Python 3.8 was removed, and the package moved to `manylinux_2_28`.
fix
Upgrade your Python environment to version 3.9 or higher.
affects: 0.14.0+
gotchaAdding new columns, reordering existing columns, or slight changes in input data can lead to different model outcomes due to the stochastic nature of some training components (e.g., feature sampling) and the pseudo-random number generator's initialization. YDF training is deterministic given identical inputs and version.
fix
For reproducible results, ensure your input dataset (columns, order, values) and YDF version are strictly identical across training runs, and explicitly set a random seed if available for stochastic parts of the algorithm.
affects: All versions
gotchaThe `verbose` parameter in learners (e.g., `GradientBoostedTreesLearner`) controls the amount of logging. The default (`verbose=1`) might produce extensive output in notebooks or consoles, potentially obscuring important information.
fix
Set `verbose=0` to suppress all logs or `verbose=2` to print all logs on all surfaces (e.g., notebook and console) if detailed debugging is needed.
affects: All versions
deprecatedThe loss metric `LAMBDA_MART_NDCG5` has been renamed to `LAMBDA_MART_NDCG`.
fix
Update your code to use `LAMBDA_MART_NDCG` for ranking tasks. The old name is deprecated but still functions.
affects: 0.11.0+
Upgrade
Version history
0.16.1latest on PyPI · released Mar 26, 2026
Audit
Dependencies
pythonrequiredRequired Python version.
pandasoptionalCommonly used for data handling, especially for CSV datasets.
tensorflowoptionalRequired for integration with TensorFlow, e.g., exporting models to TensorFlow SavedModel format via ydf-tf.
ydf-tfoptionalRequired for exporting YDF models to TensorFlow SavedModel format and loading them with TensorFlow.
Agent activity
61 hits · last 30 days
node
54
OpenAI (training)
1
Resources
ydf — pip install ydf · libregistry