Skip to content

Repository files navigation

🔍 Why Are Employees Leaving? — HR Attrition Analysis

Analyzing 1,470 IBM Employees to Reduce Turnover

Python SQL Power BI Dataset Status


📌 Project Overview

Every company loses employees — but which employees, when, and why?

This project dives into IBM's HR dataset of 1,470 employees to uncover the hidden patterns behind employee attrition. Using Python, SQL, and an interactive dashboard, we identify who is at risk of leaving and give HR teams actionable steps to retain them.

Bottom line: Overtime workers leave 3× more than others. Sales loses 1 in 5 employees every year. And 234 employees are flagged as high-risk right now.


🎯 Business Questions Answered

Question Answer Found
What is the overall attrition rate? 16.1% — 237 out of 1,470 left
Which department loses the most people? Sales — 20.6% attrition rate
Does overtime affect attrition? Yes — 3× higher (30.5% vs 10.4%)
Which age group leaves most? 18–25 year olds
Do low-salary employees leave more? Yes — leavers earned $2,046/month less
How many employees are high risk? 234 employees need urgent attention

📁 Project Structure

Why-Employees-Leave-Analysis/
│
├── 📓 Why_Employees_Leave_Analysis.ipynb   ← Main analysis notebook
├── 📊 HR_Attrition_Dashboard.html          ← Interactive visual dashboard
├── 📂 hr_attrition_data.csv               ← Original cleaned dataset
├── 📂 hr_attrition_with_risk_score.csv    ← Dataset with risk scores added
└── 📋 README.md                           ← You are here

🛠️ Tools & Technologies

Tool Purpose
Python (Pandas, Seaborn, Matplotlib) Data cleaning, EDA, visualizations
SQL (SQLite in Python) Business queries, aggregations
Power BI Desktop Executive dashboard
Jupyter Notebook End-to-end analysis
HTML/CSS Interactive web dashboard

📊 Key Findings

1. 🔴 Overtime = 3× Higher Risk

Employees who work overtime have a 30.5% attrition rate vs just 10.4% for others.

Recommendation: Cap mandatory overtime. Hire contract staff for peak periods.

2. 🏢 Sales Department is Highest Risk

Sales loses 1 in 5 employees every year (20.6% attrition rate).

Recommendation: Commission restructure + mentorship program. Saving 20 Sales Executives = ~$400K in hiring costs saved.

3. 👶 New Employees Leave Fast

Employees with 0–2 years tenure have the highest exit rate (~31%).

Recommendation: Structured 90-day onboarding program. Monthly check-ins in year 1.

4. 💰 Low Salary = High Attrition

Employees who left earned an average of $2,046/month less than those who stayed.

Recommendation: Market salary benchmarking for bottom 25% earners.

5. ⚠️ 234 Employees are High Risk Right Now

Using a rule-based Attrition Risk Score, we flagged 234 employees showing 3+ risk factors simultaneously.

Recommendation: HR to schedule quarterly retention interviews with flagged employees.


🧠 Attrition Risk Score (Unique Feature)

A custom rule-based risk scoring model — no ML needed:

df['risk_score'] = 0
df.loc[df['OverTime'] == 'Yes',          'risk_score'] += 2  # Overtime
df.loc[df['JobSatisfaction'] <= 2,        'risk_score'] += 2  # Low satisfaction
df.loc[df['YearsAtCompany'] <= 2,         'risk_score'] += 1  # New employee
df.loc[df['MonthlyIncome'] < median,      'risk_score'] += 1  # Below median pay
df.loc[df['WorkLifeBalance'] == 1,        'risk_score'] += 1  # Poor WLB
df.loc[df['EnvironmentSatisfaction'] <= 2,'risk_score'] += 1  # Bad environment

# Result:
# 🔴 High Risk  → 234 employees → 41.9% actual attrition
# 🟡 Medium     → 516 employees → 18.8% actual attrition
# 🟢 Low Risk   → 720 employees →  5.8% actual attrition

📈 SQL Queries Used

-- Attrition rate by department
SELECT Department,
       ROUND(SUM(CASE WHEN Attrition='Yes' THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 1) AS Attrition_Rate
FROM hr_data GROUP BY Department ORDER BY Attrition_Rate DESC;

-- Average salary: who left vs who stayed
SELECT Attrition, ROUND(AVG(MonthlyIncome), 0) AS Avg_Salary
FROM hr_data GROUP BY Attrition;

-- Top 5 high-attrition job roles
SELECT JobRole, ROUND(SUM(CASE WHEN Attrition='Yes' THEN 1 ELSE 0 END)*100.0/COUNT(*),1) AS Rate
FROM hr_data GROUP BY JobRole ORDER BY Rate DESC LIMIT 5;

-- Overtime vs attrition comparison
SELECT OverTime, ROUND(SUM(CASE WHEN Attrition='Yes' THEN 1 ELSE 0 END)*100.0/COUNT(*),1) AS Rate
FROM hr_data GROUP BY OverTime;

🚀 How to Run This Project

# 1. Clone the repository
git clone https://github.com/YourUsername/Why-Employees-Leave-Analysis.git

# 2. Install required libraries
pip install pandas numpy matplotlib seaborn jupyter

# 3. Open the notebook
jupyter notebook Why_Employees_Leave_Analysis.ipynb

# 4. Open dashboard in browser
# Double-click HR_Attrition_Dashboard.html
> 💡 **To view the dashboard:** Open `HR_Attrition_Dashboard.html` in your browser. If opened in Jupyter, click the **"Trust HTML"** button at the top-left to load all charts.

📂 Dataset Information

Property Detail
Source Kaggle — IBM HR Analytics Dataset
Records 1,470 employees
Features 35 columns
Missing Values 0 (perfectly clean)
Target Variable Attrition (Yes/No)

💼 Business Impact Summary

Finding Recommendation Estimated Impact
OT = 3× attrition risk Cap overtime hours 8–10% attrition reduction
0–2 yr tenure high risk Structured onboarding 30% early attrition reduction
Sales: 20.6% rate Commission + mentorship ~$400K hiring cost saved
Low salary = high churn Salary benchmarking Retain 40–50 employees/year
234 high-risk employees Quarterly HR check-ins Proactive intervention

🙋 Author

Feel free to reach out for any questions or suggestions!


⭐ If you found this project useful, please give it a star!

About

Analyzing 1,470 IBM employees to find why they leave — Python, SQL, Interactive Dashboard

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages