Skip to content
All projects

HumanForYou

predicting employee attrition

A textbook attrition case: bring together the HR data of a fictional company, derive indicators from it, then compare models under identical conditions.

  • 28

    training runs compared

    With and without rebalancing, on two pipelines, all scored on the same test set.

  • 5

    sources merged

    HR records, two satisfaction surveys, badge-in and badge-out logs, joined per employee.

  • 71%

    of leavers caught

    3 times more leavers caught thanks to rebalancing: 22% without it, with logistic regression.

Setting
Academic project, CESI
Period
February 2026
Team
Four engineering students
Role
Co-author of the project, leakage audit done afterwards
ChapterProblemContents
  1. Problem
  2. Constraints
  3. Pipeline
  4. Decisions
  5. Results
  6. Limitations and lessons learned

Problem

Who will leave, and why

HumanForYou is a fictional pharmaceutical company with 4,000 employees that considers its attrition too high. Management wants two things: to know who is likely to leave, and which levers to pull.

These are two different questions. A model that predicts well but cannot be read tells nobody what to do. It is the direct equivalent of a churn problem, applied to employees.

Constraints

A rare class, a raw log

  • Sources that look nothing alike. HR records, satisfaction surveys and time logs, to be joined on a single identifier.
  • A log that is useless as is. One column per working day, 261 working days over the year, for arrivals as for departures: it has to be summarized per employee.
  • A rare class. 16.12% of employees leave. A model answering "nobody leaves" would be right more than eight times out of ten, and useless.
  • A test set that must learn nothing. No statistic from the test set may enter data preparation.

Pipeline

From raw log to model choice

Two pipelines, identical except for one point: when the test set is set aside. Follow the one that was kept.

The notebook's two pipelines

The test set is set aside before any preparation. The pipeline kept.

The dataTwo pipelinesThe model“test set apart”“test included”Prepare scikit-learn
The dataTwo pipelines“test set apart”“test included”Prepare scikit-learnThe model

Preparescikit-learn

Medians and modes are computed on the training set alone, then applied unchanged to the test set.

Example written for the illustration.

Decisions

Recall first, and its price

Five decisions and what settled them
DecisionOption ruled outWhat settled it
Recall firstAccuracyA missed leaver costs more than a false alarm. Accuracy, on the other hand, rewards the model that flags nobody.
SMOTE, on the training set onlyDuplicating leavers; dropping stayersDuplicating pushes toward overfitting, dropping loses information. The test set keeps the real attrition rate.
Two pipelines kept side by sideFixing the first one silentlyKeeping both makes it possible to measure what the precaution changes, instead of asserting it: an average gap of 0.96 F1 points, in favor of the kept pipeline.
Seven algorithms scored on the same test setA model chosen in advanceFrom the most readable, logistic regression, to gradient boosting: the choice is defended by comparison.
XGBoost, as kept by the notebookRandom forest, recommended by the documentationBest F1 of the seven on the kept pipeline. The random forest, easier to explain to HR, is the model that was fine-tuned.

Results

What the comparison showed

Notebook scores, on its test set. How far they can be trusted is discussed in the next chapter.

Rebalancing shifts the trade-off between recall and precision; it does not remove it. The chart shows it on logistic regression. It is the model least exposed to the flaw described in the next chapter: a linear model cannot memorize an individual.

Logistic regression, without and with rebalancing

Leavers caught: 71% (With SMOTE) vs. 22% (Without SMOTE), 3.3 times more, among the test set's leavers.

Correct alerts: 37% (With SMOTE) vs. 54% (Without SMOTE), 1.5 times fewer, the price of rebalancing.

F1 score: 49% (With SMOTE) vs. 31% (Without SMOTE), 1.6 times higher, the balance of both.

  • The test set. 882 employees, 142 of them leavers, held out at their natural proportion. Stratified 80/20 split, same seed for both pipelines.
  • Rebalancing. SMOTE on the training set only: the 569 leavers brought up to the 2,959 stayers.
  • The statistical tests. Chi-squared on categorical variables, Student's t-test on continuous ones, before any modeling.
  • Tuning. Random forest, 216 combinations tested by five-fold cross-validation on the training set.
  • The limitation. The split is random, row by row. The next chapter explains what that changes.

Limitations and lessons learned

Count the people before splitting

After the project, I counted the people again. The file holds 4,410 rows, numbered as if each were an employee. It only describes 1,573 people: most appear three times, identical on every HR attribute and both surveys, target included. The replication comes from the original public dataset.

Our random split therefore scattered the copies. On average, 93.42% of test rows described someone already seen in training. The kept pipeline protected data preparation, not that boundary. The notebook's scores are inflated.

A control model measures the gap. Same HR and survey attributes, same random forest, same seed. Only the split changes: 0.9996 AUC with a random split, 0.7332 AUC once each person is kept on one side. Faced with a leaver and a stayer, the model picks the right one seven times out of ten. The diagnosis can be rerun with a single command.

AUC of the control model: 0.7332. The probability that the model ranks a leaver above a stayer. Higher is better. On a scale from 0.5 to 1: people kept apart, 0.7332; random split, 0.9996.

The dataset is fictional, derived from a public case: nothing carries over as is to a real HR department.

If I started again

  • Split off the test set before any transformation, and by person. The test set must stay what the model will see in production: data no computation has touched, and people it has never seen.
  • Read logistic regression as a detector. A linear model cannot memorize an individual. The huge gap between it and the tree-based models was the symptom, visible from the very first results table.
  • Price a missed departure with the business. The whole recall versus precision trade-off rests on that cost, assumed and never measured.