Adult Census Income Prediction
USING MACHINE LEARNING AND DATA ANALYSIS
NAME: ADITYA ANIL PATADE
GUIDED BY: SAMEER WARSOLKAR
Overview of the Project
• Objective: Predicting whether an individual earns more than $50,000 annually
based on census data
• The Adult Census Income Prediction Project aims to develop a machine learning
model to predict whether an individual’s income exceeds $50,000 per year based
on demographic and employment attributes from the U.S. Census Bureau’s Adult
dataset. This project involves several key steps, including data preprocessing,
exploratory data analysis, feature engineering, model selection, and evaluation.
• Various algorithms, such as Logistic Regression, KNeighbor Classifier, Decision
Trees and Random Forests are tested and optimized using techniques like
GridSearchCV to find the best hyperparameters. The final model’s performance
is evaluated using metrics like accuracy, precision, recall, and the F1-score. The
goal is to provide insights into the factors influencing income levels and build a
robust predictive model for practical applications in fields like economic planning
and policy-making.
Dataset Overview
• Features: age, workclass, fnlwgt, education,
[Link], [Link], occupation,
relationship, race, sex, [Link], [Link],
[Link], [Link]
• Target: income (>50K or <=50K)
Attribute Information
age: continuous – age of a Person
workclass: Where do a person works – categorical -Private, Self-emp-not-inc, Self-emp-inc, Federal-gov, Local-gov, State-gov,
Without-pay, Never-worked.
fnlwgt: This weight is assigned by the Current Population Survey (CPS). People with similar demographic characteristics should have
similar weights since it is a feature aimed to allocate similar weights to people with similar demographic characteristics – continuous
education: Degree the person has – 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: no. of years a person studied – continuous.
[Link]: No of people - Married-civ-spouse, Divorced, Never-married, Separated, Widowed, Married-spouse-absent, Married-
AF-spouse.
occupation: people's 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: people's relationship- Wife, Own-child, Husband, Not-in-family, Other-relative, Unmarried.
race: White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black.
sex: Gender - Female, Male.
[Link]: Investment gain of the person other than salary – continuous
[Link]: Loss from investments – continuous
[Link]: No. of hours a person works – continuous.
native-country: Individual person country.
income: >50K, <=50K (dependent variable, the salary is in Dollars per year)
Data Preprocessing
Handling Missing Values
R E P L A C I N G A L L I N S TA N C E S O F ' ? ' I N T H E " W O R KC L A S S " , " O C C U PAT I O N " , " N AT I V E .C O U N T RY "
C O LU M N W I T H " P R I VAT E " , ` " P R O F - S P EC I A LT Y " , " U N I T E D - S TAT E S " R E S P EC T I V E LY W H I C H W E
H AV E O BTA I N E D F R O M D E T E R M I N I N G T H E M O S T F R EQ U E N T VA LU E BY U S I N G M O D E .T H E
M O D E O F A S E T O F VA LU E S I S T H E VA LU E T H AT A P P E A RS M O S T O F T E N .
Dropping Irrelevant Columns
HERE THE FNLWGT COLUMN AND RACE COLUMN DOES NOT PROVIDE
USEFUL INFORMATION FOR THE ANALYSIS OR MODEL, SO IT HAS BEEN
REMOVED TO SIMPLIFY THE DATASET AND FOCUS ON MORE RELEVANT
FEATURES.¶
Data Visualization
• Out Of total people ,24720 (75.9%) are
less than 50K (0) and 7841(24.1%) are
greater than 50K (1).From here we can
infer that most people had salary or
income less than 50K as compared to
others.
BASED ON GENDER AND INCOME
• The figure shows that Males in
both income groups earn
significantly more than the
females respectively
BASED ON EDUCATION
Here most of the people have completed their High School Graduate,
Bachelors Degree and have completed there Masters.
BASED ON EDUCATION AND INCOME
From above plot we can conclude that majority of the work class are High school grads, bachelors degree
holders and college grads. The people who has Masters, HS-grad, Doctorate, Bachelors, Prof-school tend to
be earning more than 50K than the other degrees.
Based On Work class and Income
From above we can see that 70% of workclass fall under the private and
Private sector has the highest number of people who has income greater
than USD 50K.
DISTRIBUTION OF INCOME ACROSS AGE
We infer that min salary of most of the population is in their 20's which is a valid as it is the starting time of a career.
Here we can conclude that Age and salary are in direct proportion with each other. The data is left skewed as there are a
very few people who work after 60's,therefore,the chances of salary being more than 50k is very less.
BASED ON GENDER
We can see from the graph that
67% of employees are males while
only 33% are females.
SEPARATING NUMERICAL & CATEGORICAL DATA
Here we have separated numerical
data for feature scaling.
SEPARATING CATEGORICAL COLUMN
Here we have separated categorical
column for label encoding.
LABEL ENCODING
Label encoding is a technique used
to convert categorical text data into
numerical data so that machine
learning algorithms can process it.
FEATURE SCALING
Feature scaling process ensures
that the numerical data is
standardized, which is a common
preprocessing step in machine
learning to improve model
performance and convergence.
CONCATENATING NUMERICAL DATA AND
CATEGORICAL DATA
Here we have concatenated label encoded Categorical data and
feature scaled numerical data. This process is useful when preparing
data for further analysis or machine learning tasks, where both
numerical and categorical features need to be included in the same
SPLIT TING DATA INTO X (FEATURES) & Y (TAREGET
Here we separated the data into features(x) and target(y) variable
SAMPLING
Above visualization helps to confirm that the oversampling process has
balanced the distribution of income categories.
75.92% of the employees earn 50K USD or less while the remaining Here we have preferred Upsampling over downsampling because it
24.08% earn above 50k USD.. Here we need to do up sampling to
remove bias in training model as the data is imbalanced helps to preserve all original data and improves the representation of
the minority class without losing valuable information. However, the
choice between upsampling and downsampling should be made based
MODEL SELECTION
Here we have Imported necessary
libraries and modules for machine
learning, model evaluation, and
hyperparameter tuning & Split the
data into training and testing sets
Further we have initialize different
machine learning classifiers.
Here we have define a function to
train a model, make predictions, and
print a classification report
MODEL EVALUATION
LOGI STI C REGR ESSI ON ALGOR I THM USI NG GRI D SEARCH
CV
Grid Search Cross-Validation (Grid Search CV) is a technique used in machine learning to find the best
hyperparameters for a given model by exhaustively searching through a specified subset of the hyperparameter
space.
Random Forest Algorithm using Grid Search CV
Results
• From here, we can conclude that Random Forest
Classifier has the highest accuracy with a score of
90.86%.
• This indicates that the Random Forest algorithm
performs the best among the ones listed for the
given dataset.
• Logistic Regression has the lowest accuracy with a
score of 76.71%. This suggests that it is the least
effective model in this comparison for this dataset.
CONCLUSION
• We can conclude that Random Forest Classifier has the highest accuracy
with a score of 90.86%. This indicates that the Random Forest algorithm
performs the best among the ones listed for the given dataset.
• The Random Forest Classifier is the most accurate model in this
comparison, achieving the highest accuracy, while Logistic Regression
has the lowest accuracy. The other classifiers fall in between, with the K
Neighbors and Decision Tree models showing strong performance but
not quite matching the Random Forest's accuracy
THANK YOU