1 of 26

A Comparative Analysis of Income Level Prediction

ESAD KOPRU

2 of 26

Table of Contents

  1. Data Exploration
  2. Split Data into Training and Test
  3. Classification:�
    1. Logistic Regression
    2. Classification: Tree Based Classification
    3. Classification: Random Forest
    4. Classification: Linear SVM
  4. Discussion and Conclusion

3 of 26

Data

4 of 26

Data Exploration

5 of 26

NA Values

  • First attempt was assigning average weights, however, later in the random forest analysis, the NA’s occurred again, so my second approach was to remove all NA values.
  • inc_clean <- DMwR::knnImputation(inc, k=5, scale=T, meth="weighAve")
  • summary(inc_clean)
  • inc_clean <- inc[complete.cases(inc), ]

6 of 26

Data Exploration

Income level vs. age, education num, marital status; married people earns higher than single or widowed.

, occupation

7 of 26

Income Level vs. Occupation, Marital Status

8 of 26

Data Exploration

9 of 26

Income Level vs. Race, Gender

10 of 26

Divide dataset into Training and Test

  • set.seed(12345)
  • # split training and test datasets, 80% and 20%
  • train_sample <- sample(nrow(inc_clean), round(nrow(inc_clean)*0.8))
  • inc_clean_train <- inc[train_sample, ]
  • inc_clean_test <- inc[-train_sample, ]

11 of 26

Logistic Regression Model

  • log.base.model <- glm(incomelevel~., data=inc_clean_train, family="binomial")

  • vif(log.base.model) Error in vif.default(log.base.model) : there are aliased coefficients in the model

  • Education and educationnum are representing the same information, one with categorical and the latter is with numeric. So I removed the categorical education

12 of 26

Logistic Regression Model 2

  • inc_clean <- inc_clean[,-4]
  • inc_clean_train <- inc_clean_train[,-4]
  • inc_clean_test <- inc_clean_test[,-4]log.updated.model2 <- glm(incomelevel~age+workclass+fnlwgt+educationnum+ occupation+relationship+race+sex+capitalgain+capitalloss+ hoursperweek, data=inc_clean_train, family="binomial")

13 of 26

Final Logistic Regression model

14 of 26

Final logistic regression model VIF

15 of 26

Logistic Regression model Evaluation

Misclassification => 818+377/7788 = 0.153

16 of 26

Tree based Classification

  • tree.incomelevel <- tree(incomelevel~., data=inc_clean_train)
  • Error in tree(incomelevel ~ ., data = inc_clean_train) :
  • factor predictors must have at most 32 levels

17 of 26

Pruning Tree

18 of 26

Tree Evaluation

Misclassification => 291+964/7788 = 0.1611

19 of 26

Random Forest Classification

The gini index shows that age, education, and the relationship are all important variables.

20 of 26

Random Forest Tuning

  • ######### Tune Random Forest ###########
  • > mtry <- tuneRF(inc_clean_train, inc_clean_train$incomelevel, ntreeTry=10,
  • + stepFactor=1.5,improve=TRUE, trace=TRUE, plot=TRUE, doBest=TRUE)
  • mtry = 3 OOB error = 0.16% Searching left ... mtry = 2 OOB error = 0.52% -2.190979
  • TRUE Searching right ... mtry = 4 OOB error = 0.09% 0.4730805 TRUE
  • rf2.incomelevel <- randomForest(incomelevel~., data=inc_clean_train, mtry=4,
  • importance=TRUE) > varImpPlot(rf2.incomelevel)

21 of 26

Random forest Variable Importance Plot

22 of 26

Random Forest Evaluation

Misclassification => 439+692/7788 = 0.1452

23 of 26

SVM Classification, Linear

  • svm.fit <- svm(incomelevel~.,data=inc_clean_train, cost=0.01, kernel='linear')
  • summary(svm.fit)

24 of 26

SVM Evaluation, Linear

Misclassification => 818+377/7788 = 0.1534

25 of 26

Comparison

Logistic Regression

Pruned Tree

Optimized Random Forest

Linear SVM

Misclassification => 818+377/7788 = 0.1534

Misclassification => 439+692/7788 = 0.1452

Misclassification => 291+964/7788 = 0.1611

Misclassification => 818+377/7788 = 0.153

26 of 26

Discussion and Conclusion

  • Fine tuning of SVM could perform better (both for linear and polynomial).
  • The tuned random forest model has the lowest classification rate (optimized mtry variable).
  • Logistic regression model is strong in predicting the income level.