pyethnicity:
What is it?
pyethnicity is a Python package to predict race from name and location and sex from first name. To the best of the author's knowledge, it outperforms all existing open-source models. It does this by training a Bidirectional LSTM on the largest, most comprehensive dataset of name and self-reported race thus far. It uses voter registration data from all 50 states. Additionally, it incorporates location features and improved versions of Bayesian Improved Surname Geocoding and Bayesian Improved Firstname Surname Geocoding to form an ensemble model that achieves up to 36.8% higher F1 scores than the next-best performing model. Finally, it provides CFPB-compliant and up-to-date versions of BISG and BIFSG.
Usage:
Please see https://pyethnicity.readthedocs.io/en/latest/ for full documentation.
Installing
The easiest way is to install pyethnicity is from PyPI using pip:
pip install pyethnicity
Running
Pyethnicity exposes several functions. It supports block group, tract, and zip code level features. Each function takes in a scalar or array-like of inputs and returns a polars DataFrame of the input and the predictions.
import pyethnicity
zcta = 27106
tract = 72153750502
first_name = "cangyuan"
last_name = "luo"
pyethnicity.bisg(last_name, zcta=zcta)
pyethnicity.bifsg(first_name, last_name, zcta=zcta, tract=tract)
pyethnicity.predict_race_fl(first_name, last_name)
pyethnicity.predict_race_flg(first_name, last_name, tract=tract)
pyethnicity.predict_race(first_name, last_name, zcta=zcta)
Performance
pyethnicity
rethnicity
ethnicolr
Please see the correpsonding paper "Can We Trust Race Prediction?" for more details.
TODO:
- Re-train model to support Native American and Multiracial.
This package is still in active development. Please report any issues!
Metadata
Release files for pyethnicity 0.0.27
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyethnicity-0.0.27.tar.gz | 38.8 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyethnicity-0.0.27-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 77.6 MB
Release files / pyethnicity-0.0.27.tar.gz
| Download URL | pyethnicity-0.0.27.tar.gz |
|---|---|
| Size | 38.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
349178001f90480a9be78819833ee34942f6383af3444d5bbb5736199e7f858f
|
|
BLAKE2b-256 checksum How to use checksums |
7832d97cd3362b7fa4550e679943138b049cdbd18a29f67b3115fcbb930dfedc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / pyethnicity-0.0.27-py3-none-any.whl
| Download URL | pyethnicity-0.0.27-py3-none-any.whl |
|---|---|
| Size | 38.8 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0f8a495c9cfa71facc9a1eb602c6d591ae9c02d038362396ef8cf2d36a0bf42
|
|
BLAKE2b-256 checksum How to use checksums |
4bb997321a68f6db4026dad998bd5c5799eb96a893c58644940f88bf305ea7b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for pyethnicity 0.0.27
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.