SketchFill: Sketch-Guided Code Generation for Imputing Derived Missing Values

Yunfan Zhang, Changlun Li, Yuyu Luo, Nan Tang · DOI

Introduction

Missing Value Imputation (MVI) is a critical bottleneck in data science, often consuming nearly half of a data scientist's preparation time. While traditional statistical methods like mean/median imputation or machine learning approaches like K-Nearest Neighbors (KNN) work for simple, independent missing values, they frequently fail at Derived Missing Value Imputation (DMVI).

DMVI occurs when a missing value is a functional derivative of other variables—for example, a "Total" column in a retail dataset that must be calculated as the sum of "Price," "Quantity," and "Tax." Standard Large Language Model (LLM) approaches, such as Chain-of-Thought (CoT) prompting, often struggle with these tasks because they tend to hallucinate arithmetic results or fail to grasp complex multi-step table structures.

Examples of Derived Missing Value Imputation (DMVI) tasks across simple, intermediate, and complex domains.

Methodology: The SketchFill Framework

The core innovation of SketchFill is its sketch-guided code generation pipeline, which mimics the workflow of a human data scientist. Instead of asking an LLM to directly "fill the gap," SketchFill guides the model through a structured reasoning process that prioritizes code generation over direct calculation.

The SketchFill architecture, illustrating the iterative workflow from Meta-Sketch to executable Python code.

The framework is composed of four primary modules:

  1. Domain-Sketch Generator: The system provides a Meta-Sketch—a high-level template of logical steps (e.g., "Find related columns," "Draft solution"). The LLM uses this to create a Domain-Sketch tailored to the specific dataset (e.g., "Step 1: Use the pandas df.isnull() function on the 'close' column").
  2. Self-Reflected Code Generator: This module translates the abstract Domain-Sketch into executable Python code. By forcing the model to output code rather than raw numbers, SketchFill leverages the LLM's superior logical reasoning while offloading arithmetic to the Python interpreter.
  3. The Reflector & Evaluator: This iterative loop acts as a "unit test" for the generated logic. The system tests the code on a small "clean" subset of the data where values are known. If the code produces an error or an incorrect result, the Reflector analyzes the failure (e.g., identifying a wrong row index) and updates the Domain-Sketch for a subsequent attempt.
  4. Summarizer: Once the formula is verified, the Summarizer generalizes the code into a robust Python function that can be applied to the entire "dirty" dataset via an Executor.

Experimental Setup and Datasets

To ensure the framework could generalize beyond memorized formulas, the authors evaluated SketchFill across five diverse domains:

  • Finance (Bajaj): Stock market indicators like Simple Moving Average (SMA5).
  • Health (BMI): Calculating Body Mass Index from height and weight.
  • Retail (Supermarket): Calculating totals and gross income from unit prices and taxes.
  • Transportation (GreenTrip): Taxi fare components including tolls and tips.
  • Gaming (LOLChampion): Performance metrics like Kill-Death-Assist (KDA) ratios.

Key Results and Insights

SketchFill established a new state-of-the-art for automated DMVI, demonstrating that LLMs are more reliable as programmers than as calculators. Key performance metrics include:

  • Significant Accuracy Gains: SketchFill achieved 56.2% higher accuracy than standard Chain-of-Thought (CoT) prompting and 78.8% higher accuracy than MetaGPT.
  • Zero-Error Imputation: On simpler datasets like BMI and Supermarket, the framework achieved near-perfect results (0.0 RMSE), effectively reverse-engineering the underlying mathematical logic.
  • Robustness: Even on noisy datasets like LOLChampion, where column names are often ambiguous, SketchFill maintained a significant lead over traditional statistical methods like MICE and KNN.

Conclusion and Future Work

SketchFill demonstrates that the "reasoning gap" in LLMs can be bridged by providing structured reasoning paths (sketches) and empirical feedback loops. While the system excels at single-step and moderately complex formulas, extremely complex multi-step financial indicators (like RSI) still pose a challenge. Future research will focus on improving the framework's ability to handle categorical data and enhancing the Reflector's logic for datasets with high noise levels in the reference samples.

Summary updated

BibTeX
@misc{zhang2024sketchfill,
  author = {Yunfan Zhang and Changlun Li and Yuyu Luo and Nan Tang},
  title = {{SketchFill: Sketch-Guided Code Generation for Imputing Derived Missing Values}},
  year = {2024},
  eprint = {2412.19113},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.19113},
}
Figure