Predicting Income
1. Background Scenario
Note: This is a hypothetical scenario.
It’s 2005 and the median U.S. income is $50,000. My client ‘Grow Smart’, a nonprofit, is looking to roll out a program nation wide in the U.S. to help people future plan. They want to help people under the current median income to achieve a median U.S. income and for people already above the median income grow into a better financial state. They will use my recommendations to look into and/or use key features in building their program for rollout.
I hypothesized that creating a classification model for ‘Grow Smart’ would allow them make accurate predictions on how to get people to the goal of making a median income and beyond. Using census data I built a classification model to make predictions on wether an individual would make above or below $50K.
2. The Data
Data Specs:
Income Classification: Census data from Kaggle.
32,561 rows/ 15 columns
Target:
Income: 0 = (<=$50K) and 1 = (>$50K)
Features Key:
- age: continuous.
- education: Bachelors, Some-college, 11th, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9th, 7th-8th, 12th, Masters, 1st-4th, 10th, Doctorate, 5th-6th, Preschool.
- education-num: continuous.
- marital-status: Married-civ-spouse, Divorced, Never-married, Separated, Widowed, Married-spouse-absent, Married-AF-spouse.
- occupation: Tech-support, Craft-repair, Other-service, Sales, Exec-managerial, Prof-specialty, Handlers-cleaners, Machine-op-inspct, Adm-clerical, Farming-fishing, Transport-moving, Priv-house-serv, Protective-serv, Armed-Forces.
- relationship: Wife, Own-child, Husband, Not-in-family, Other-relative, Unmarried.
- race: White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black.
- sex: Female, Male.
- hours-per-week: continuous.
- native-country: United-States, Cambodia, England, Puerto-Rico, Canada, Germany, Outlying-US(Guam-USVI-etc), India, Japan, Greece, South, China, Cuba, Iran, Honduras, Philippines, Italy, Poland, Jamaica, Vietnam, Mexico, Portugal, Ireland, France, Dominican-Republic, Laos, Ecuador, Taiwan, Haiti, Columbia, Hungary, Guatemala, Nicaragua, Scotland, Thailand, Yugoslavia, El-Salvador, Trinadad&Tobago, Peru, Hong, Holand-Netherlands.
3. Methodology
After data acquisition, cleaning, EDA, and feature engineering I decided to use data from just the USA (90% of the data comes from the USA) and filtered for people working 40+ hors per week leaving me with 21K rows 21,378 rows / 44 columns to work with.
Tools Used:
- Google Sheets, Pandas and Numpy for data acquisition, EDA, cleaning, and feature engineering
- Imblearn for resampling unbalanced classes
- Sklearn for modeling and parameter tuning
- Grid Search for hyper-parameter optimization
- Matplotlib and Seaborn for data and model visualization
4. EDA & Feature Engineering Workflow
After some initial EDA in Google Sheets the rest of the EDA and data cleaning was preformed in Python.
Starting with the Null values, they showed as ‘?’ in the dataset. They were treated as a missing value and replaced with NaN in the resulting DataFrame.
Some on the feature column names and cells had a space in the beginning (‘ age’) so it had to be stripped.
A few features were not going to be used so they were dropped.
At this point the dataframe looked like this.
Next I filtered for just the U.S. and people working 40+ hours per week.
I checked for Null values and dropped them.
prior shape: (22174, 11) post shape: (21378, 11)
I wanted to more of an idea of all the data I was working with so I ran a loop to view all of the unique values in each feature.
Next I decided to rename some of the features.
It was necessary to change certain data into numerical data.
The rest of the non-numeric data was then changed to dummy variables for use in modeling. This changed my dataframe rows shape from 11 to 51 rows.
When the dummies were created it gave new columns for just the Null values in each feature, so they were dropped.
To prepare the data for modeling I had to drop the Target variable from the ‘X’ variable and I dropped ‘country_United-States’ since all the data in the dataframe is already filtered for the U.S.
A Target ‘y’ was then created for ‘income’.
5. Charts & Key Insights
In this section I created charts to help display interesting information that was found within the data set. I will go through each chart and explain what they show and how I interpret the information.
Note: Income is the target, 0 = (<=$50K) and 1 = (>$50K)
For the first chart I created a box plot to represent the relationship between age and income int he dataset.
The median age for a person making <=50K is 38 and the median for a person makeing >50K is 42.
What I gather from this is that the longer a person is in the workforce the more likely they are to make >50k. Most people who are in a carrer tend to move up in salary over time.
In the next box plot we see the relationship between education and income
People who have a median education level of ‘some college’ are more likely to make <=50k. People with a median education level of at least an associates degree are more likely to make >50k.
Education-num key code:
1 = Preschool
2 = 1st-4th
3 = 5th-6th
4 = 7th-8th
5 = 9th
6 = 10th
7 = 11th
8 = 12th
9 = HS-grad
10 = Some-college
11 = Assoc-voc
12 = Assoc-acdm
13 = Bachelors
14 = Masters
15 = Prof-school
16 = Doctorate
In the next chart we have a histogram of hours worked per week.
This shows that the majority of people working 40hrs per week make <=50k but even if a person works more than 40hrs they are not more likely to make >50k.
In his next chart we have a histogram of the connection between family relationship and income.
When it comes to family relationship the husban is the least likely to make <=50k and the most likely to make >50k. The situation is flipped for the wife. ‘Other Relative’ (nephew, grandparent, etc.) in this catigory, someone not making much or any income, is the most likley out of everyone to be making <=50k and least likely to be making >50k.
For the next chart we will take a look at the coefficient probabilities of all the features. I used the divide by 4 rule which will be explained after viewing the chart.
After feature engineering I was left with 43 features. Marked with the Red arrows are the standout coefficients. Below is a chart of their values.
I used the ‘divide by 4 rule’ to get my coefficients.
Interpretation using the ‘divide by 4 rule’: Using ‘Relationship- Wife’, a 1 unit increase (being a wife) will result in no more than a 32% positive difference in the probability that they will make >$50K.
All of the standout negative coefficients fall under ‘Marital Status’ (single people). What this is saying is that being single will decrease the the probability that one will make $50k by or up to 50%.
6. Modeling
I implemented several different models for this project. The data was Scaled, grid search was used to optimize hyper-parameters for Logistic Regression and implemented a Train, Validate, Test Split: 60/20/20.
I will be showing code for one of the models the others are similar in setup.
Mean Accuracy: 0.803
Config: {'C': 1.0, 'penalty': 'l1', 'solver': 'liblinear'} Score on train: 0.803
Score on val: 0.802
Simple Logistic Regression train F1: 0.649 Simple Logistic Regression val F1: 0.641
Below is a chart of scores for all of the models prior to the final model.
I chose to go with Logistic Regression for the final model.
Accuracy Score on test: 0.796 Logistic Regression Test Data F1: 0.614
7. Recommendations
Based off of my findings my recommendations to ‘Grow Smart’ would be:
- Look into targeting and helping people under the median age of 38.
- Work out how to best help people reach at least 2 years of college to gain an associates degree.
- Look into targeting wives for the program and look deeper into the ‘Other Relative’ category and how best to assist those demographics.
- Look into strategies for targeting and helping individuals that are single within the ‘Marital Status’ category.
