Skip to main content

ethnicolr2: Predict Race and Ethnicity From Name

image image Python version image Documentation

A Pytorch implementation of ethnicolr with new models that make different assumptions (for instance, this package has models trained on unique names) than ethnicolr. The package uses the US census data and the Florida voting registration data to build models to predict the race and ethnicity (non-Hispanic whites, non-Hispanic Blacks, Asians, Hispanics, and Other) based on first and last name or just the last name. For notebooks underlying the package, see here.

Caveats and Notes

If you picked a random person with the last name 'Smith' in the US in 2010 and asked us to guess this person's race (as measured by the census), the best guess is the modal race of the person named Smith (which you can get from the census popular last name data file). It is the Bayes Optimal Solution. So what good are predictive models? A few things---if you want to impute race and ethnicity for last names that are not in the census file, which can be because of errors, infer the race and ethnicity in different years than when the census was conducted (if some assumptions hold), infer the race of people in different countries (if some assumptions hold), etc. The biggest benefit comes in cases where both the first and last name are known.

Install

We strongly recommend installing [ethnicolor2]{.title-ref} inside a Python virtual environment (see venv documentation)

pip install ethnicolr2

Example

To predict race/ethnicity using the Florida Last Name Model to a file with first and last names

import pandas as pd
from ethnicolr2 import pred_fl_last_name, pred_fl_full_name
df = pd.read_csv("docs/source/examples/input-with-header.csv")
pred_fl_last_name(df, lname_col = "last_name")


names = [
 {"last": "sawyer", "first": "john", "true_race": "nh_white"},
 {"last": "torres", "first": "raul", "true_race": "hispanic"},
]
df = pd.DataFrame(names)
df = pred_fl_full_name(df, lname_col = "last", fname_col = "first")

      last  first true_race   preds
0  sawyer   john  nh_white nh_white
1  torres   raul  hispanic hispanic

Authors

Rajashekar Chintalapati, Suriyan Laohaprapanon, and Gaurav Sood

Contributor Code of Conduct

The project welcomes contributions from everyone! In fact, it depends on it. To maintain this welcoming atmosphere and to collaborate in a fun and productive way, we expect contributors to the project to abide by the Contributor Code of Conduct.

🔗 Adjacent Repositories

  • appeler/ethnicolr — Predict Race and Ethnicity Based on the Sequence of Characters in a Name
  • appeler/ethnicolor — Race and Ethnicity based on name using data from census, voter reg. files, etc.
  • appeler/parsernaam — AI name parsing. Predict first or last name using a DL model.
  • appeler/instate — instate: predict the state of residence from last name using the indian electoral rolls
  • appeler/naamkaran — generative model for names

Metadata

Release files for ethnicolr2 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ethnicolr2 0.3.3
File Size Uploaded
ethnicolr2-0.3.3.tar.gz 5.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ethnicolr2 0.3.3
File Interpreter ABI Platform
ethnicolr2-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 MB

Release files / ethnicolr2-0.3.3.tar.gz

Download URL ethnicolr2-0.3.3.tar.gz
Size 5.1 MB
Tags Source
SHA-256 checksum
How to use checksums
f19f4ad3f7144d35bd994d562c3c3efc45a0c9389ec1421492e54f9e14586f34
BLAKE2b-256 checksum
How to use checksums
90e830a2c462d724888970608c51526f8a22b13700d8e58674992e2e77e3c074
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Release files / ethnicolr2-0.3.3-py3-none-any.whl

Download URL ethnicolr2-0.3.3-py3-none-any.whl
Size 5.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
a3a8cb33dc247d1e4a7f9a81c2778b3b49563db5dde1e9124bfd8f6f3c9123f3
BLAKE2b-256 checksum
How to use checksums
d7b405a38f9d2c71322592ff9db6cc33c8b1436202de00aed3238f228c90f701
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.1.4

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page