Skip to content

Latest commit

Β 

History

History
159 lines (122 loc) Β· 4.73 KB

File metadata and controls

159 lines (122 loc) Β· 4.73 KB

HR Analytics with SQL & Python

This project explores employee attrition patterns using a mix of PostgreSQL for querying and Python for analysis & visualization.
It is designed as a portfolio project β€” showing end-to-end data handling, from raw CSV β†’ database β†’ SQL analysis β†’ Python stats β†’ machine learning β†’ reproducible deliverables.


πŸ“‚ Project Structure

HR-Analytics-SQL-Python/
β”œβ”€ queries/
β”‚    β”œβ”€ basic_checks.sql
β”‚    β”œβ”€ overall_attrition.sql
β”‚ 	 β”œβ”€ dept_attrition.sql
β”‚ 	 β”œβ”€ salary_analysis.sql
β”‚ 	 β”œβ”€ jobrole_attrition.sql
β”‚ 	 β”œβ”€ tenure_attrition.sql
β”‚ 	 β”œβ”€ overtime_attrition.sql
β”‚ 	 └─ age_gender_attrition.sql
β”‚ 	 
β”œβ”€ notebook/
β”‚    β”œβ”€ hr_analysis.ipnyb
β”‚    β”œβ”€ eda_summary.ipnyb
β”‚    └─ figures/
β”‚    		β”œβ”€univariate/
β”‚    		β”‚ 	β”œβ”€ age_distribution.png
β”‚    		β”‚ 	β”œβ”€ attribution_balance.png
β”‚    		β”‚ 	β”œβ”€ department_counts.png
β”‚    		β”‚ 	β”œβ”€ monthly_income_distribution.png
β”‚    		β”‚ 	└─ overtime_counts.png
β”‚    		β”‚ 	
β”‚    		β”œβ”€bivariate/
β”‚    		β”‚ 	β”œβ”€ attrition_vs_age.png
β”‚   		β”‚ 	β”œβ”€ attrition_vs_dept.png
β”‚    		β”‚ 	β”œβ”€ attrition_vs_gender.png
β”‚    		β”‚ 	β”œβ”€ attrition_vs_jobrole.png
β”‚    		β”‚ 	β”œβ”€ attrition_vs_maritalstatus.png
β”‚    		β”‚ 	β”œβ”€ attrition_vs_monthlyincome.png
β”‚    		β”‚ 	β”œβ”€ attrition_vs_overtime.png
β”‚    		β”‚ 	└─ attrition_vs_tenure.png
β”‚    		β”‚ 	
β”‚    		└──eda_summary/
β”‚    			β”œβ”€ age_tenure_analysis.png
β”‚    			β”œβ”€ attrition.png
β”‚    			β”œβ”€ attrition_gender_maritalstatus.png
β”‚    			β”œβ”€ dept_and_jobroles.png
β”‚    			β”œβ”€ monthlyincome_vs_attrition.png
β”‚    			└─ overtime_impact.png
β”œβ”€ data/
β”‚    └─ ibm_hr.csv
β”‚ 
β”œβ”€ results/
β”‚    β”œβ”€ overall_attrition.csv
β”‚    β”œβ”€ dept_attrition.csv
β”‚    β”œβ”€ salary_analysis.csv
β”‚    β”œβ”€ jobrole_attrition.csv
β”‚    β”œβ”€ tenure_attrition.csv
β”‚    β”œβ”€ overtime_attrition.csv
β”‚    └─ age_gender_attrition.csv
β”‚
β”œβ”€ LICENSE	
β”œβ”€ requirements.txt
└─ README.md # Project Overview (this file)

🎯 Objectives

  • Understand employee attrition drivers using SQL queries
  • Perform exploratory data analysis (EDA) with Python
  • Run statistical checks (e.g., overtime vs attrition significance)
  • Build a basic predictive model (logistic regression)
  • Deliver visuals, CSV outputs, and notebooks in a clean repo

πŸ› οΈ Tools Used

  • Database: PostgreSQL
  • Querying: SQL
  • Analysis: Python (Pandas, NumPy, Matplotlib, Seaborn, Statsmodels, Scikit-learn)
  • Version Control: Git + GitHub

πŸ“Š Key Findings

  • Overall attrition: ~16% of employees
  • Departmental differences: R&D had higher attrition vs HR & Sales
  • Overtime: Employees working overtime are significantly more likely to leave
  • Job roles: Sales reps & lab technicians showed higher attrition
  • Income effect: Lower monthly income strongly correlates with attrition
  • Predictive model: Logistic regression flagged Overtime, MonthlyIncome, JobRole, and Age as the strongest predictors.

πŸ“Š Key Findings (Simple Version)

  • About 1 in 6 employees left the company during the observed period.
  • Working overtime is one of the biggest factors linked to leaving.
  • Lower salary employees tend to leave more often than higher salary ones.
  • Certain job roles and departments (like Sales and Lab Techs) have higher turnover.
  • Younger employees are more likely to quit compared to older ones.

πŸ“Œ Deliverables

  • Reproducible SQL queries β†’ queries/
  • Query outputs β†’ results/
  • Python notebooks with EDA, stats, and model β†’ notebook/
  • Figures for visualization β†’ notebook/figures/
  • README.md (project overview)

πŸš€ How to Run

  1. Clone this repo

    git clone https://github.com/ajx7/HR-Analytics-SQL-Python.git
    cd HR-Analytics-SQL-Python
  2. Install requirements

    pip install -r requirements.txt
  3. Set up PostgreSQL DB

    • Create a database
    • Import data/ibm_hr.csv
  4. Run SQL scripts in queries/

  5. Open notebooks in notebook/ for Python analysis


πŸ“– Dataset Source

IBM HR Analytics Employee Attrition & Performance dataset (publicly available on Kaggle): IBM HR Analytics Dataset – Kaggle


βš–οΈ License

This project is licensed under the MIT License β€” free to use with attribution.


About

This project was built as part of a portfolio refresh, showing end-to-end data analysis and reproducibility skills.