From Strings to Data Science: a Practical Framework for Automated String Handling

John W. van Lith, Joaquin VanschorenarXiv 2021

Introduction

Data scientists often spend up to 60% of their time on data cleaning, with categorical strings representing a significant bottleneck. While machine learning algorithms are inherently "math-first," real-world data is frequently "string-first," containing names, addresses, zip codes, and dates.

The current industry standard relies on manual preprocessing, where humans must identify column types and manually convert them into numerical formats (e.g., mapping Likert scales to 1-5). This process is tedious, error-prone, and difficult to scale. Existing automated tools often oversimplify by treating all strings as basic categories, thereby losing rich internal structures—such as the geographical proximity of zip codes—or inherent ordinality.

The Automated Pipeline

The authors propose a multi-stage framework designed to automate the "messy middle" of data science by intelligently handling string data.

The multi-stage pipeline for automated string handling, from type inference to final encoding.

The pipeline consists of five key stages:

  1. Type Inference: Utilizing Probabilistic Finite-State Machines (PFSMs) based on regular expressions, the system identifies nine specific string types, including coordinates, emails, filepaths, and zip codes.
  2. Missing Value & Outlier Handling: The framework employs Little’s test to detect "missingness" and applies appropriate imputation techniques (e.g., mean/mode or multivariate methods). It also corrects minor typos using string metrics.
  3. Type-Specific Processing: Domain-specific logic is applied to identified types. For instance, sentences are simplified to nouns, and zip codes are converted to latitude/longitude coordinates via the geopy library.
  4. Statistical Type Prediction: For strings without a clear pattern, a pre-trained Gradient Boosting Classifier determines if they are Nominal (unordered) or Ordinal (ordered). This classifier evaluates features like string uniqueness and GloVe word embeddings.
  5. Encoding: Finally, the data is encoded. Nominal data uses techniques like MinHash or Similarity encoding. Ordinal data utilizes a novel approach: sentiment intensity analysis (FlairNLP) to automatically determine logical order (e.g., "very bad" < "good").

Evaluation and Datasets

The framework was evaluated on diverse real-world datasets from Kaggle, UCI, and OpenAddresses. These included specialized types like FIFA 19 player data (dates/URLs) and San Francisco Crime data (days), as well as nominal/ordinal benchmarks like Mushroom classification and Wine Reviews. The authors manually annotated these datasets to create a ground-truth for testing the statistical type predictor.

Key Results and Insights

The framework demonstrated that automated handling can match or exceed manual preprocessing quality.

Framework performance across various datasets compared to OrdinalEncoder and TargetEncoder baselines.
  • Performance Gains: Type-specific processing led to a 10% improvement in downstream model performance on several datasets.
  • Efficiency: By simplifying complex strings and converting numerical strings (e.g., ">10") into integers, the framework reduced model training time by at least 10% on half of the tested datasets.
  • Predictive Accuracy: The statistical type predictor achieved 98% accuracy in distinguishing between nominal and ordinal columns.
  • Sentiment as Order: A key innovation is using sentiment analysis (FlairNLP) as a proxy for ordinality, allowing the system to automatically rank categories like "Poor" and "Excellent" without manual intervention.

Conclusion

While the framework shows great promise, limitations remain. The reliance on regular expressions for PFSMs can be brittle if string formats deviate from expected patterns. Additionally, the use of heavy NLP libraries like FlairNLP increases computational overhead. Future work may involve "human-in-the-loop" systems where the framework flags low-confidence type predictions for manual verification.

The project is available as an open-source Python library on GitHub.

Summary updated

BibTeX
@misc{lith2021from,
  author = {John W. van Lith and Joaquin Vanschoren},
  title = {{From Strings to Data Science: a Practical Framework for Automated String Handling}},
  year = {2021},
  eprint = {2111.01868},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2111.01868},
}
Figure