ethnicolr2: Predict Race and Ethnicity From Names

CI PyPI Version Python Version Downloads

ethnicolr2 is a modern PyTorch-based machine learning package that predicts race and ethnicity from names using LSTM neural networks. It’s trained on US Census data and Florida voter registration data to provide accurate predictions based on:

  • Last name only (census model or Florida model)

  • First and last name combined (Florida full name model)

Quick Start

# Install ethnicolr2
uv add ethnicolr2
# or
pip install ethnicolr2
import pandas as pd
from ethnicolr2 import pred_fl_last_name

# Predict from last names
df = pd.DataFrame({'last': ['Smith', 'Zhang', 'Rodriguez']})
result = pred_fl_last_name(df, lname_col='last')
print(result)

Key Features

🎯 High Accuracy

Trained on US Census data and Florida voter registration with proven accuracy for demographic prediction.

Key Concepts
⚡ Modern PyTorch

Built with PyTorch 2.x for efficient neural network inference with LSTM models.

API Reference
🔧 Easy Integration

Both Python API and command-line interface for seamless integration into your workflow.

Command Line Interface

Documentation Sections

🚀 Getting Started

Installation, quickstart guide, and core concepts to get you up and running quickly.

Installation
📚 User Guide

Detailed tutorials, examples, and best practices for different use cases.

Census Data Models
📖 API Reference

Complete API documentation with all classes, functions, and parameters.

API Reference
🛠️ Development

Contributing guidelines, testing, and development setup information.

Contributing to ethnicolr2

Supported Prediction Categories

The models predict one of five race/ethnicity categories:

  • nh_white: Non-Hispanic White

  • nh_black: Non-Hispanic Black

  • hispanic: Hispanic

  • asian: Asian

  • other: Other

Available Models

Model

Input

Training Data

Use Case

Census Last Name

Last name only

US Census 2000/2010

General population predictions

Florida Last Name

Last name only

FL voter registration

State-specific predictions

Florida Full Name

First + Last name

FL voter registration

Highest accuracy predictions

Indices and Tables