Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Recommenders team Recommenders Criteo Dataset

From Leeroopedia
Revision as of 16:28, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Recommenders_team_Recommenders_Criteo_Dataset.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Recommender Systems, Data Loading, Benchmark Datasets
Last Updated 2026-02-10 00:00 GMT

Overview

Provides utilities for downloading, extracting, and loading the Criteo Display Advertising Challenge (DAC) dataset in both Pandas and PySpark DataFrame formats.

Description

The criteo module supports the Criteo DAC dataset, a standard benchmark for click-through rate prediction models. It offers two dataset sizes: sample and full, with corresponding download URLs defined in CRITEO_URL. The dataset schema is defined in DEFAULT_HEADER as 1 label column, 13 integer feature columns (int00 through int12), and 26 categorical feature columns (cat00 through cat25). download_criteo uses maybe_download to fetch the tar.gz archive. extract_criteo safely extracts the tarball with path traversal protection that validates all member paths are within the target directory. load_pandas_df orchestrates the full download-extract-load pipeline using pd.read_csv with tab separation. load_spark_df provides the same pipeline for PySpark, including Databricks support via dbutils for copying files to DBFS. get_spark_schema constructs a StructType schema mapping the first 14 header fields to IntegerType and the remaining 26 to StringType.

Usage

Use load_pandas_df or load_spark_df at the start of a click-through rate prediction experiment to load the Criteo DAC dataset. Specify size="sample" for quick prototyping or size="full" for production-scale training.

Code Reference

Source Location

Signature

def load_pandas_df(
    size="sample",
    local_cache_path=None,
    header=DEFAULT_HEADER,
) -> pd.DataFrame

def load_spark_df(
    spark,
    size="sample",
    header=DEFAULT_HEADER,
    local_cache_path=None,
    dbfs_datapath="dbfs:/FileStore/dac",
    dbutils=None,
) -> pyspark.sql.DataFrame

def download_criteo(size="sample", work_directory=".") -> str

def extract_criteo(size, compressed_file, path=None) -> str

def get_spark_schema(header=DEFAULT_HEADER) -> StructType

Import

from recommenders.datasets.criteo import load_pandas_df, load_spark_df

I/O Contract

Inputs

Name Type Required Description
size str No (default: "sample") Dataset size. Either "sample" or "full".
local_cache_path str or None No (default: None) Path where to cache the tar.gz file locally. If None, uses a temporary directory.
header list No (default: DEFAULT_HEADER) Column names for the dataset (1 label + 13 int + 26 cat features).
spark pyspark.SparkSession Yes (for load_spark_df) Active Spark session.
dbfs_datapath str No (default: "dbfs:/FileStore/dac") DBFS path for Databricks environments.
dbutils object No (default: None) Databricks dbutils object for file operations.
compressed_file str Yes (for extract_criteo) Path to the compressed tar.gz file.
work_directory str No (default: ".") Working directory for downloading.

Outputs

Name Type Description
return (load_pandas_df) pd.DataFrame Criteo DAC dataset as a pandas DataFrame with label, integer, and categorical feature columns.
return (load_spark_df) pyspark.sql.DataFrame Criteo DAC dataset as a PySpark DataFrame with a typed schema.
return (download_criteo) str File path of the downloaded tar.gz archive.
return (extract_criteo) str File path of the extracted dataset text file.
return (get_spark_schema) StructType Spark schema with IntegerType for label/int columns and StringType for categorical columns.

Usage Examples

Basic Usage

from recommenders.datasets.criteo import load_pandas_df, load_spark_df

# Load sample dataset as a pandas DataFrame
df = load_pandas_df(size="sample")
print(df.shape)       # (100000, 40) - 1 label + 13 int + 26 cat features
print(df.columns[:5]) # ['label', 'int00', 'int01', 'int02', 'int03']

# Load with a persistent cache directory
df = load_pandas_df(size="sample", local_cache_path="/tmp/criteo_cache")

# Load as a PySpark DataFrame
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
spark_df = load_spark_df(spark, size="sample")
spark_df.printSchema()

Dependencies

  • pandas - DataFrame construction and CSV parsing
  • os / tarfile - File path management and tar extraction
  • pyspark (optional) - Spark DataFrame and schema types
  • recommenders.datasets.download_utils - maybe_download and download_path
  • recommenders.utils.notebook_utils - is_databricks for environment detection

Related Pages

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment