Sitemap
Press enter or click to view image in full size
Source: canva.com

HR Analytics: Predicting Employee Attrition with Machine Learning

7 min readFeb 19, 2022

--

Introduction

This project aims to discover insights that will help a company make conscious decision about hiring talents and improve employee satisfaction and retention. The report will go through exploratory data analysis, data preparation, and use machine learning to drive the decision making process.

Target Audience

The target audience of this project would be executives or Human Resources leader who are interested in uncovering insights around employee attrition. The modeling of employee attrition prediction will help the target audience make an informed decision about why employees attrition on a broad level and consider options that can prevent attrition of talents.

Data Sources and Exploratory Data Analysis

1. Data Sources

The dataset is found on kaggle.com, it is a fictional dataset created by data scientists from IBM. It is fictional because it is unlikely that a company would release real data on their employees to protect their personal information. However, the project will include processes that would be adaptable and helpful for an analysis for a real dataset.

2. Exploratory Data Analysis

Based on this summary, the dataset has a total of 35 columns with 1470 unique entries. There is no null data or duplicates in the dataset, making it more usable.

From here we can see the statistical summaries of the numerical data in the dataset. For example, the mean age of the employees documented in the dataset is 36.92. The average EnvironmentSatisfation rating 2.72; average hourly rate is 65.89. Most of the columns are self-explanatory, according to the sources of the dataset, for ratings, a higher number means a higher rating/satisfaction.

Some variables that are more related to the target variable Attrition: EnvironmentSatisfaction, JobInvolvement, Job level, JobSatisfaction, MonthlyIncome, StockOptionalLevel, TotalWorkingYears, YearsAtCompany, YearsInCurrentRole, YearswithManager.

Since the correlation analysis only includes numercial variables, the below graphs will explore the categorical variables.

This plot shows the number of attritions reported by Education Field. It seems that although technical degree, marketing, and human resources fields make up a small proportion of the dataset, the proportions of the attrited employees are higher. Below we look at the percentage of attrited employees by education field.

About 30.5% of overtime employees have attrited, meaning that it is a factor that needs to be accounted for employee attrition.

The percentage of attrition among Travel_Frequently group is much higher than the other two groups.

This graph shows that about 250 employees departed the company, while about 1200 employees stayed. There is also a larger proportion of male in this dataset. The above statistics shows that 15% of female employees attrited and 17% of male employees attrited. However, considering that male employees make up a big portion of the sample, this difference is unlikely statistically significant.

It seems that the for non-attrition, an average employee tends to have worked longer at the company. However, for married and attrited employees, the distribution of Years in Current Role span from 0 to 7.5. Overall, about half of the employees are married and only a small percentage of them chooses to leave the company.

This statistics show the percentage of attrition by Job role, almost 40% of attrited employees are sales representatives, followed by laboratory technicians and human resources positions.

Data Preparation and Modeling

1. Data Preparation

It shows that the categorical variables that we transformed do show a relationship with the target variable. Especially OverTime and JobRole.

2. Feature Selection

This heatmap again tells us how related the variables to Attrition. We will pick the ones that have an absolute correlation value greater than 0.1 for our model

3. Modeling

Using Scikit-learn, alogistic regression model was created to predict attrition. And dataset was split into 80% training and 20% testing data.

I picked the logistic regression model to classify our data because our target feature, Attrition, is a binary feature. We used the ‘newton-cg’ solver because we are predicting Attrition using multiple features at once.

4. Model Accuracy

Confusion Matrixes for Test/Train Predictions

Press enter or click to view image in full size
Press enter or click to view image in full size

The training confusion matrix shows the number of predicted values and the actual values. The model has an accuracy of 87%. It does very well in predicting non-attrited employees, about 98% of the time based on the recall score. However, the recall score for attrited employees is only 26%.

Our f1 score on the testing set was not less than the f1 score on the training set, so we likely did not overfit. However, the recall score for the testing data is larger than for the training data, this means that our model identifies attrition better in an unfamiliar set of data.

Receiver Operating Characteristic(ROC) curve is a plot of the true positive rate against the false positive rate. It shows the tradeoff between sensitivity and specificity. The AUC curve for this model is 0.84, which means it is moderately a good classifier.

5. Visualization for Model Prediction

In order to see the predicted results more clearly, I created an interactive Tableau dashboard to visualize the predicted attritions along with the demographics of employees.

Press enter or click to view image in full size

Discussion

1. Observations

Based on the data analysis early in the project, we found that there are some numerical variables that are correlated with Attrition: EnvironmentSatisfaction, JobInvolvement, Job level, JobSatisfaction, MonthlyIncome, StockOptionalLevel, TotalWorkingYears, YearsAtCompany, YearsInCurrentRole, YearswithManager.

However, there are some other categorical variables that are also important. For example, we found that in the dataset,

* employees with a background in technical degrees, human resources, and marketing fields have a higher tendency in attrition compared to medical, life sciences and other fields.

* 30% of overtime employees have attrited compared to employees that don’t work overtime. Frequent Business Travels also contribute to attrition.

* In terms of Job Role, almost 40% of attrited employees are sales representatives, followed by laboratory technicians and human resources positions.

* Stock Option level is also a big factor that contributes to attrition. i.e. if the company offers more stock options for the employees, they are less likely to attrit.

* The analysis also shows that the higher the employee is involved in their jobs, the less likely they are to leave the company.

2. Implications

Based on our observations, we can draw the following implications for companies:

* Employees with background in technical degrees, human resources, and marketing fields need to be looked after based on their job roles.

* Companies should reduce employee’s overtime work to increase job satisfaction

* Companies need to offer more incentives for sales representatives, laboratory technicians and human resources positions. For example, by reducing their work hours and offering some flexibility.

* Companies should consider offering more stock options for employees.

* For all positions, companies should help increase employees’ involvement in the job to show that they can make a true contribution to the company.

3. Limitations

In this project, a logistic regression model was created to predict employee attritions, with accuracy of 86% and an AUC score of 84%. The model can predict attrition 29% of the time with an F1 score of 41% for positive attrition. This model serves as a good classifier for attritions of employees, but it also might lead to false negatives, i.e. employees that attrit but shown as non-attrition. Companies can use the model for reference but it only helps to a certain extent with employee attritions. Companies need to spend some time considering the important factors that contribute to employee attritions based on these models and improving them to prevent loss of talent.

Conclusion

At the start of this project, we identified the importance of talent retention for a company and collected a dataset on employee information and attrition. We then completed an exploratory data analysis, creating heatmaps to show correlations between variables, and visualizations to understand the demographics and features of attrited employees. Using logistic regression algorithms, we built a model that helps predict employee attrition with an accuracy of 86%. Then we concluded that there are some variables that are important factors in an employee’s decision to attrit such as education fields, job roles, satisfaction, etc. We also developed implications for companies with actions to consider in order to prevent future loss of talent.

Overall, this project was a great practice utilizing data science concepts and machine learning algorithms. The methods used in this project can be used to help a company predict employee attrition using their own data on their employees. The insights uncovered through classification algorithms can be used to develop action items that help prevent future loss of talent.

Sources

Building a Logistic Regression in Python Step-by-Step

Understanding Logistic Regression in Python

Scikit-Learn Logistic Regression Documentation

Python Sklearn Logistic Regression Tutorial with Example

Precision and Recall

--

--

Mandy Nicole Hong
Mandy Nicole Hong

Written by Mandy Nicole Hong

👩🏻‍💻 Marketing Data Scientist | Diver Exploring Depths Beyond Data 🌊 | Lifelong Learner, Adventurer & Creator 🌟