Skip to main content

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

Project description

ethnicolr2: Predict Race and Ethnicity From Name

https://github.com/appeler/ethnicolr2/workflows/test/badge.svg https://img.shields.io/pypi/v/ethnicolr2.svg https://static.pepy.tech/badge/ethnicolr2

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 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
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.

License

The package is released under the MIT License.

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.1.1.tar.gz (16.9 MB view details)

Uploaded Source

Built Distribution

ethnicolr2-0.1.1-py2.py3-none-any.whl (17.1 MB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: ethnicolr2-0.1.1.tar.gz
  • Upload date:
  • Size: 16.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ethnicolr2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2dc02e5fc3672d01bce6f5aa18891e733815665bb58345a53caf2a641f9835fe
MD5 8365a888e407faa571e2713e3dd62a2d
BLAKE2b-256 d0f89096e0fd6312287fbd5ba7f7983bc02c8668ce2fdda0cb818be3ac53288e

See more details on using hashes here.

File details

Details for the file ethnicolr2-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: ethnicolr2-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.1 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ethnicolr2-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9eba907eade0ac7696830385d9b437b847854fba73540d313f8c7ddf75bdc713
MD5 929e156bc5b12d8a6b46fb9b82013bff
BLAKE2b-256 2973e7310b3fb16d3c0e02cae541dec46a90e6a8e6ac622c992bb45d2b6614e3

See more details on using hashes here.

Supported by

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