Sitemap
Abraham, E.P

Abraham, E.P

Predicting Employee Attrition With Machine Learning

10 min readAug 3, 2026

--

Employee attrition can be expensive for an organisation.

When employees leave, a company may have to spend more money recruiting and training replacements. Productivity may also fall, while teams lose valuable experience and knowledge.

But what if employee data could help organisations identify patterns connected with attrition before more employees leave?

That was the focus of this project.

Our team, The DataSmiths, analysed the IBM HR Employee Attrition dataset to identify factors associated with employee turnover and build a machine-learning model that could predict whether an employee was likely to stay or leave.

We followed the complete data science process, from cleaning and exploring the data to building, evaluating and interpreting three classification models.

Project Goals

The main goals of this project were to:

  1. Explore the employee dataset and identify factors associated with attrition.
  2. Build classification models that predict whether an employee is likely to stay or leave.
  3. Compare the models and select the best-performing model.
  4. Identify the most important factors linked with employee attrition.
  5. Provide practical recommendations for improving employee retention.

Project Workflow

We completed the project using the following steps:

  1. Data collection
  2. Data cleaning
  3. Exploratory data analysis
  4. Data visualisation
  5. Feature engineering and encoding
  6. Train-test split
  7. Feature scaling
  8. Model building
  9. Model evaluation
  10. Interpretation and recommendations

Data Collection

We used the IBM HR Analytics Employee Attrition and Performance dataset.

The original dataset contained:

  • 1,470 employee records
  • 35 columns
  • Employee demographic information
  • Job-related information
  • Satisfaction ratings
  • Work experience
  • Salary and promotion information
  • Employee attrition status

The target variable was Attrition.

It had two possible values:

  • No — the employee stayed
  • Yes — the employee left
A preview of the IBM HR Employee Attrition dataset

Data Cleaning

Before analysing the data, we checked it for common data-quality problems.

The dataset had:

  • No missing values
  • No exact duplicate rows
  • No duplicated column names

We removed four columns:

  • EmployeeCount
  • Over18
  • StandardHours
  • EmployeeNumber

The first three columns contained the same value for every employee, so they could not help explain differences in attrition.

EmployeeNumber was removed because it was only a unique employee identifier.

After cleaning, the dataset contained:

  • 1,470 rows
  • 31 columns

The notebook’s cleaning checks confirmed zero missing values and duplicate records after the unnecessary columns were removed.

Final checks after cleaning the employee dataset

Exploratory Data Analysis

We carried out exploratory data analysis to understand the employees and identify patterns linked with attrition.

The overall employee attrition rate was approximately 16.12%.

This means that most employees stayed, while a much smaller number left.

Because the two groups were not equal, the target variable was imbalanced. This later became important when evaluating the models.

Most employees stayed with the organisation, while approximately 16% left

Overtime and Attrition

Overtime produced one of the strongest patterns in the analysis.

Employees who worked overtime had an attrition rate of approximately 30.53%, compared with about 10.44% among employees who did not work overtime.

This means that employees working overtime left at almost three times the rate of employees who did not work overtime.

Although this does not prove that overtime directly caused attrition, it shows a strong relationship that the organisation should investigate.

Employees who worked overtime recorded a much higher attrition rate.

Business Travel

Frequent business travellers had a higher attrition rate than employees who travelled rarely or did not travel.

Frequent travel may affect an employee’s personal time, workload and work-life balance.

This suggests that companies should monitor travel demands and provide adequate support to employees who travel regularly.

Job Roles

Attrition was not evenly distributed across job roles.

The analysis showed comparatively high attrition among:

  • Sales Representatives
  • Laboratory Technicians
  • Human Resources employees

The relationship became even more noticeable when job role and overtime were examined together.

Some job roles recorded considerably higher attrition when overtime was required, showing that employee characteristics may interact rather than operate separately.

Attrition levels differed across job roles and overtime groups.

Age and Attrition

Employees between the ages of 18 and 25 recorded the highest age-group attrition rate.

Within this group:

  • 123 employees were represented
  • 44 employees left
  • The attrition rate was approximately 35.77%

The attrition rate was lower among several older age groups.

This may suggest that younger employees are more likely to explore new opportunities or have weaker ties to the organisation.

However, age alone does not fully explain why an employee leaves.

Employees aged 18–25 recorded the highest attrition rate.

Income, Experience and Distance From Home

Employees who left generally had:

  • Lower monthly income
  • Fewer total working years
  • Shorter company tenure
  • Slightly longer travel distances from home

The difference in distance from home was not as strong as the differences observed for overtime or business travel.

No single numerical feature had a very strong relationship with attrition. This showed that several employee factors needed to be considered together when building the predictive models.

Feature Engineering and Encoding

Machine-learning models require numerical data.

We therefore converted the target variable as follows:

  • No became 0
  • Yes became 1

Binary variables such as Gender and Overtime were also converted into numbers.

Variables with several categories were converted using one-hot encoding. These included:

  • Business Travel
  • Department
  • Education Field
  • Job Role
  • Marital Status

After encoding, the prepared dataset contained:

  • 45 total columns
  • 44 predictor variables
  • 1 target variable
Categorical employee variables were converted into numerical columns for modelling.

Train-Test Split

The data was divided into:

  • 80% training data
  • 20% testing data

This produced:

  • 1,176 training records
  • 294 testing records

Stratification was used to maintain approximately the same proportion of employees who stayed and left in both datasets.

Get Abraham, E.P’s stories in your inbox

Join Medium for free to get updates from this writer.

The training data was used to teach the models, while the testing data was used to measure how well they performed on unseen records.

Feature Scaling

StandardScaler was applied before training the Logistic Regression model.

Scaling places numerical features on a similar range, preventing variables with larger values from dominating the model.

Decision Tree and Random Forest did not require scaling, so they were trained using the original unscaled features.

Models Built

We trained three classification models.

Logistic Regression

Logistic Regression was used as the baseline model.

It estimates the probability that an employee belongs to the attrition class based on the employee’s characteristics.

Decision Tree

The Decision Tree model makes predictions through a series of simple decision rules.

It divides the employee data into smaller groups until it reaches a final prediction.

Random Forest

Random Forest combines the predictions of many Decision Trees.

For this project, the model used 100 trees and combined their answers to make its final predictions.

Model Evaluation

The models were evaluated using:

  • Accuracy
  • Precision
  • Recall
  • F1-score
  • ROC-AUC

What the metrics mean

Accuracy shows the percentage of all predictions that were correct.

Precision shows how often the model was correct when it predicted that an employee would leave.

Recall shows how many employees who actually left were correctly identified.

F1-score balances precision and recall.

ROC-AUC measures how well the model separates employees who stayed from employees who left.

Model Comparison

The performance chart shows that Logistic Regression produced the strongest overall results among the three models.

It achieved:

  • 86.05% accuracy
  • 61.54% precision
  • 34.04% recall
  • 43.84% F1-score
  • 80.79% ROC-AUC

Random Forest recorded an accuracy of 83.33% and a ROC-AUC score of 78.64%. However, its recall was only 6.38%, meaning that it failed to identify most of the employees who actually left.

The Decision Tree produced the highest recall at 36.17%, slightly above Logistic Regression. However, it recorded lower accuracy, precision, F1-score and ROC-AUC.

Although none of the models identified every employee who left, Logistic Regression provided the strongest combination of overall accuracy, precision, F1-score and ability to separate the two employee groups.

For this reason, it was selected as the best-performing model for the project.

Comparison of the evaluation scores for the three models.

Choosing the Best Model

Logistic Regression performed best overall.

It had the highest:

  • Accuracy
  • Precision
  • F1-score
  • ROC-AUC

The Decision Tree had slightly higher recall, meaning it identified slightly more employees who left.

However, its accuracy, precision, F1-score and ROC-AUC were much lower.

The Random Forest had fairly good accuracy, but its recall was only 6.38%. This means that it missed most of the employees who actually left.

Logistic Regression therefore provided the most balanced and reliable overall performance.

Press enter or click to view image in full size
Logistic Regression produced the highest ROC-AUC score.

Understanding the Logistic Regression Results

The confusion matrix provides a closer look at the predictions made by the selected Logistic Regression model.

Out of the 294 employees in the testing dataset, the model correctly predicted that 237 employees would stay. It also correctly identified 16 employees who actually left.

However, the model incorrectly classified 10 employees who stayed as likely to leave. More importantly, it missed 31 employees who actually left, predicting that they would stay.

In summary, the model produced:

  • 237 correct stay predictions
  • 16 correct attrition predictions
  • 10 incorrect attrition warnings
  • 31 missed attrition cases

These results show that the model was much better at identifying employees who stayed than employees who left.

Its recall score of 34.04% means it correctly identified approximately one-third of the employees who actually left. Therefore, although Logistic Regression performed best overall, its predictions should be used as an early-warning signal rather than a final decision-making tool.

The model correctly identified most employees who stayed but missed several employees who left.

Important Factors Linked With Higher Attrition

We examined the Logistic Regression coefficients to understand which features influenced its predictions.

The factors linked with a higher predicted chance of attrition included:

  • Overtime
  • Frequent business travel
  • More years since the last promotion
  • Having worked at several companies
  • Greater distance from home
  • Being single
  • Working as a Laboratory Technician
  • Working as a Sales Representative
  • Working as a Sales Executive

Overtime had the strongest positive coefficient, making it the most important higher-attrition factor identified by the model.

Factors Linked With Lower Attrition

The following factors were linked with a lower predicted chance of attrition:

  • More total working years
  • Higher environment satisfaction
  • Higher job satisfaction
  • Older age
  • More years with the current manager
  • Higher job involvement
  • More years in the current role

These findings suggest that experienced and satisfied employees with stronger workplace relationships may be less likely to leave.

The findings show relationships within the dataset. They do not prove that any factor directly caused an employee to stay or leave.

The strongest factors linked with higher predicted attrition.
The strongest factors linked with lower predicted attrition.

Recommendations

Based on the analysis, the organisation should consider the following actions.

Reduce unnecessary overtime

Management should review employee workloads and monitor employees who work overtime regularly.

Improve promotion opportunities

Employees should have clear career paths, promotion requirements and regular discussions about professional growth.

Support frequent business travellers

Travel schedules should be reviewed, with enough rest time and support provided to employees who travel often.

Improve job and workplace satisfaction

The company should collect regular employee feedback and address common workplace concerns.

Pay attention to higher-risk job roles

Management should investigate the challenges faced by Laboratory Technicians, Sales Representatives and Sales Executives.

Strengthen manager-employee relationships

Managers should hold regular check-ins, provide feedback and support employees’ development.

Support employees who live far from work

Flexible work arrangements or better work schedules may reduce the stress caused by long commutes.

Use the model as an early-warning tool

The model can help HR identify employees who may require additional support.

However, it should not be used as the only basis for employment decisions.

Limitations

Although Logistic Regression performed best overall, the project had some limitations.

First, the dataset was imbalanced because there were many more employees who stayed than employees who left.

Second, Logistic Regression identified only about 34% of the employees who actually left.

Third, the analysis was based on one dataset, so the findings may not apply equally to every organisation or industry.

The findings also show associations, not definite causes.

Finally, employee behaviour can change over time due to changes in management, salary, workplace culture and personal circumstances.

For these reasons, the model should support human judgement rather than replace it.

Final Thoughts

Through this project, The DataSmiths explored the factors linked with employee attrition and compared three machine-learning models.

Logistic Regression produced the strongest overall results, with an accuracy of 86.05% and a ROC-AUC score of 80.79%.

Although the Decision Tree had slightly higher recall, Logistic Regression produced the most balanced and reliable performance.

The analysis showed that overtime, frequent business travel, delayed promotions, distance from home and certain job roles were linked with higher attrition.

Higher job satisfaction, environment satisfaction, job involvement, work experience and stronger manager relationships were linked with lower attrition.

These findings can help the organisation make better-informed employee-retention decisions.

However, the model should be treated as an early-warning tool and used alongside employee feedback and human judgement.

Project Resources

GitHub Repository:
View the complete project on GitHub

Project Team:
The DataSmiths

--

--