Predict Race/Ethnicity Based on Sequence of Characters in the Name
Project description
ethnicolr2: Predict Race and Ethnicity From Name
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("ethnicolr2/data/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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ethnicolr2-0.3.1.tar.gz.
File metadata
- Download URL: ethnicolr2-0.3.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
351c9354270f961e1f3f1c465d096b2af8cb80215f86775262e64c02093cd206
|
|
| MD5 |
e1f5ba926ab23267a99f9e71ec39b520
|
|
| BLAKE2b-256 |
cd1b51ef2e9941feb7df97978b783a14690f0cf1d682936b38e9a81864e7b8a6
|
Provenance
The following attestation bundles were made for ethnicolr2-0.3.1.tar.gz:
Publisher:
python-publish.yml on appeler/ethnicolr2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ethnicolr2-0.3.1.tar.gz -
Subject digest:
351c9354270f961e1f3f1c465d096b2af8cb80215f86775262e64c02093cd206 - Sigstore transparency entry: 780539379
- Sigstore integration time:
-
Permalink:
appeler/ethnicolr2@9071b1026fda340521f608cc1eb492047e05ebaa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/appeler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9071b1026fda340521f608cc1eb492047e05ebaa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ethnicolr2-0.3.1-py3-none-any.whl.
File metadata
- Download URL: ethnicolr2-0.3.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4ca519553d3ba163d43dc0645751a790c5f069113647c79221ba7af2f73e1e4
|
|
| MD5 |
37335a4575791fcd1f1f8648180e69b8
|
|
| BLAKE2b-256 |
fc5617b774fd94235fa5e7dfd874acafe7bace10a4b7be7959d31e15eff8c106
|
Provenance
The following attestation bundles were made for ethnicolr2-0.3.1-py3-none-any.whl:
Publisher:
python-publish.yml on appeler/ethnicolr2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ethnicolr2-0.3.1-py3-none-any.whl -
Subject digest:
d4ca519553d3ba163d43dc0645751a790c5f069113647c79221ba7af2f73e1e4 - Sigstore transparency entry: 780539380
- Sigstore integration time:
-
Permalink:
appeler/ethnicolr2@9071b1026fda340521f608cc1eb492047e05ebaa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/appeler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9071b1026fda340521f608cc1eb492047e05ebaa -
Trigger Event:
workflow_dispatch
-
Statement type: