Employee attrition is a critical challenge for organizations, leading to high replacement costs and loss of valuable talent. This project aims to build a robust Machine Learning pipeline to predict which employees are at risk of leaving, allowing the HR department to take proactive retention measures.
Instead of optimizing for overall accuracy (which is misleading in highly imbalanced HR datasets), this project prioritizes Recall. By implementing a Linear SVM paired with SMOTEENN, the final model successfully identifies ~81% of at-risk employees, providing HR with a highly actionable "watch list" to conduct stay-interviews before resignation letters are drafted.
- Language: Python
- Libraries: Pandas, Scikit-learn, Imbalanced-learn, Matplotlib, Seaborn
- Data Preprocessing: Custom Pipelines, RobustScaler, OneHotEncoding.
- Handling Imbalanced Data:
SMOTEENN(Synthetic Minority Over-sampling Technique + Edited Nearest Neighbours). - Modeling: Logistic Regression, Random Forest, KNN, and Support Vector Machines (SVM).
- Hyperparameter Tuning:
GridSearchCVwith Stratified K-Fold Cross Validation.
By extracting coefficients from the Tuned Linear SVM, we identified the top drivers of employee turnover:
- Job Role (Laboratory Technician): Highest risk factor, indicating potential issues with compensation or role design.
- OverTime: Both excessive overtime and strict "no overtime" policies correlate with higher attrition (burnout vs. disengagement).
- Business Travel: Frequent travelers and non-travelers leave more often than those who travel moderately.
- Role Stagnation (
YearsInCurrentRole): Lack of internal mobility significantly drives talent away.
- Algorithm: Linear Support Vector Machine (SVM)
- Threshold: Default (0.50) - chosen for best practical HR balance.
- Recall (Class 1):
0.809(Caught 29 out of 47 leaving employees) - ROC AUC:
0.830
V11_Employee_Attrition_Performance_prediction.ipynb: The complete End-to-End code (EDA, Pipeline, Modeling, Evaluation).WA_Fn-UseC_-HR-Employee-Attrition.csv: The HR dataset used for training and testing. Kaggle
- Clone the repository:
git clone https://github.com/omarDlgaber/HR-Attrition-Prediction.git - Install the required dependencies.
- Run the Jupyter Notebook.