Instate: predict the state of residence from last name
Project description
Using the Indian electoral rolls data (2017), we provide a Python package that takes the last name of a person and gives its distribution across states.
Potential Use Cases
India has 22 official languages. And to serve such a diverse language base is a challenge for businesses and surveyors. To the extent that businesses have access to the last name (and no other information) and in absence of other data that allows us to model a person’s spoken language, the distribution of last name across states is the best we have.
Installation
We strongly recommend installing indicate inside a Python virtual environment (see venv documentation)
pip install instate
Examples
from instate import last_state last_dat <- pd.read_csv("last_dat.csv") last_state_dat <- last_state(last_dat, "dhingra") print(last_state_dat)
API
instate exposes 3 functions.
last_state
takes a pandas dataframe, the column name for the df column with the last names, and produces a dataframe with 31 more columns, reflecting the number of states for which we have the data.
- ::
from instate import last_state df = pd.DataFrame(‘last_name’: [‘Dhingra’, ‘Sood’, ‘Gowda’]}) last_state(df, “last_name”).iloc[:, : 5] >>> last_name __last_name andaman andhra arunachal 0 Dhingra dhingra 0.001737 0.000744 0.000000 1 Sood sood 0.000258 0.002492 0.000043 2 Gowda gowda 0.000000 0.528533 0.000000
pred_last_state
takes a pandas dataframe, the column name with the last names, and produces a dataframe with XX more columns, reflecting the number of states for which we have the data.
state_to_lang
takes a pandas dataframe, the column name with the state, and appends census mappings from state to languages
from instate import state_to_lang df = pd.DataFrame({'last_name': ['dhingra', 'sood', 'gowda']}) state_last = last_state(df, "last_name") small_state = state_last.loc[:, "andaman":"utt"] state_last["modal_state"] = small_state.idxmax(axis = 1) state_to_lang(state_last, "modal_state")[["last_name", "modal_state", "official_languages"]] last_name modal_state official_languages 0 dhingra delhi Hindi, English 1 sood punjab Punjabi 2 gowda andhra Telugu
Data
The underlying data for the package can be accessed at: https://doi.org/10.7910/DVN/ZXMVTJ
Evaluation
The model has a top-3 accuracy of 85.3% on unseen names.
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
Built Distribution
Hashes for instate-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07cf7176a1482aa56e3ba2a68145dd97753edadf5b1dfbb9371225d37bce7e63 |
|
MD5 | 5e5e521bf75bf461d6544456e5322e97 |
|
BLAKE2b-256 | facc80325679a33a46c6cd0e40d0004648de201dd25f702f0ee2acef6fc4857d |