Skip to main content

Predict Race/Ethnicity Based on Sequence of Characters in the Name

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ethnicolr2-0.3.2.tar.gz (37.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ethnicolr2-0.3.2-py3-none-any.whl (37.9 MB view details)

Uploaded Python 3

File details

Details for the file ethnicolr2-0.3.2.tar.gz.

File metadata

  • Download URL: ethnicolr2-0.3.2.tar.gz
  • Upload date:
  • Size: 37.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ethnicolr2-0.3.2.tar.gz
Algorithm Hash digest
SHA256 f3de7549e752c5a7be7fbf9ea0f2af63cb4f4d5a5edd6d5f31a22c024bb2e041
MD5 2b0cc6d60084cefc390f72f0cc3d26fc
BLAKE2b-256 c812dff02d4b7ea84d9b6a3799ffa1405790804a777af4ce60fb19398a5acffd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ethnicolr2-0.3.2.tar.gz:

Publisher: python-publish.yml on appeler/ethnicolr2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ethnicolr2-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: ethnicolr2-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 37.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ethnicolr2-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cb1832cfa16e4bbe35e2ab9fff498fdb6d81058fba137e96b5c7be9dbecd01c
MD5 5ca3f0cde037e6e4b0231f4e7a3d68cb
BLAKE2b-256 fa54320ee41205afa5a0ef680afcaaf42d799c6745224b48910a9494015d6b47

See more details on using hashes here.

Provenance

The following attestation bundles were made for ethnicolr2-0.3.2-py3-none-any.whl:

Publisher: python-publish.yml on appeler/ethnicolr2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page