Skip to content

About

90-day workforce attendance & punctuality data analytics case study (3,550 shifts) using Pandas, Seaborn, and Jupyter.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

17 Commits

Folders and files

Repository files navigation

πŸ“Š 90-Day Workforce Attendance Analytics & Predictive ML Intelligence

CI Python Scikit-Learn XGBoost Streamlit Pandas Seaborn License: MIT GitHub Stars

⭐ If you find this workforce analytics case study or the Streamlit simulator helpful, please consider starring this repository!

An end-to-end data analytics and workforce intelligence case study examining 90 days of employee attendance, punctuality dynamics, commute friction, and day-of-week behavioral patterns across 50 employees and 3,550 recorded shifts.

Features an executive Streamlit HR policy simulator demonstrating that a 15-minute flexible grace window reduces tardiness by 67.8% across departments, and a flagship XGBoost predictive classifier forecasting severe late arrivals with ROC-AUC = 0.908.


πŸ“Œ Executive Summary

Modern enterprise HR leaders face significant productivity friction due to inflexible attendance expectations and transit bottlenecks. This project applies statistical modeling, time-series aggregation, exploratory data analysis (EDA), and machine learning to uncover operational bottlenecks and guide evidence-based workforce scheduling policies.

Core Metrics at a Glance (90 Days / 3,550 Shifts)

  • Total Shifts Analyzed: 3,550 across 50 employees and 5 departments.
  • Strict 9:00 AM Tardiness: 40.5% (1,436 shifts logged as late).
  • Severe Tardiness (>15 mins): 13.0% (462 shifts).
  • Minor Delay Absorption: 67.8% of late shifts fall within a 1–15 minute micro-delay window (morning signals, elevator queues).
  • Policy Simulation Impact: Shifting scheduled start from 9:00 AM to 9:30 AM (or adopting a 15m grace window) reduces tardiness by 67.8% across all departments.
  • Predictive Model ROC-AUC: 0.9040 on test split (0.8821 Β± 0.0166 on 5-fold CV with 0% data leakage).

πŸŽ›οΈ Interactive Streamlit Simulator (streamlit_app.py)

An interactive executive workforce intelligence dashboard that allows HR managers to simulate policy changes and test real-time ML risk predictions:

  • πŸ“‚ Custom Biometric / Punch CSV Uploader: Upload any organization's raw punch logs or use the pre-calibrated 90-day dataset.
  • Executive Shift Start & Grace Window Simulator: Adjust shift start timing (9:00 AM ➑️ 9:30 AM) and grace periods (0m to 30m) with live impact calculations and an Exportable Executive Policy Impact Memo (.md).
  • Individual Late-Arrival Risk Forecaster: Input department, commute distance (km), day of week, punch method, and employee baseline reliability to predict late-arrival probability with prescriptive HR recommendations.
  • πŸ” Local Factor Explainability Breakdown: Bar chart breakdown quantifying individual risk factors (commute distance delta, Monday peak choke, department exposure, and baseline profile).
  • πŸ‘€ Employee 360Β° Profile Studio: Deep-dive into an individual employee's 90-day attendance record, punctuality score, day-of-week late patterns, and activity logs.
  • Model Benchmark & Explainability Studio: Inspect cross-validation metrics, ROC curves, feature importance gain hierarchies, and confusion matrices.
  • Raw Data Explorer: Filterable shift table with dynamic CSV export.

Launch the dashboard:

streamlit run streamlit_app.py

Run automated tests:

python -m unittest tests/test_pipeline.py

Deploy with Docker:

docker build -t attendance-analytics .
docker run -p 8501:8501 attendance-analytics

πŸ€– Predictive Machine Learning Benchmark

We benchmarked three classification architectures using a 5-Fold Stratified Cross-Validation protocol (strictly leak-free with train-fold target encoding) to predict severe late arrivals (>15 minutes):

Model Architecture 5-Fold CV ROC-AUC Test ROC-AUC Test Accuracy Test Precision Test Recall Test F1-Score
Logistic Regression 0.8901 Β± 0.0162 0.9073 91.3% 72.7% 52.2% 0.6076
Random Forest (150 Trees) 0.8865 Β± 0.0158 0.9034 90.7% 78.3% 39.1% 0.5217
XGBoost (Flagship Classifier) 0.8821 Β± 0.0166 0.9040 91.3% 84.1% 40.2% 0.5441

Key ML Architectural Drivers

  1. Commute Distance ($40.8%$ Gain): Urban transit distance along Ahmedabad's SG Highway and SP Ring Road is the single strongest predictor of morning arrival volatility.
  2. Commute Distance Γ— Monday Interaction ($24.6%$ Gain): Peak morning congestion on Mondays introduces severe non-linear transit delays for employees commuting $>18\text{ km}$.
  3. Department Structural Factor ($14.2%$ Gain): Field-heavy departments (Sales and Operations) face higher external transit exposure compared to Engineering and HR.

πŸ“ˆ Visual Proofs & Model Diagnostics

1. ROC-AUC Benchmark Curves

Cross-model comparison demonstrating strong discrimination ability ($\text{AUC} > 0.90$) across Logistic Regression, Random Forest, and XGBoost against random chance ($\text{AUC} = 0.50$).

ROC Curves


2. Feature Importance Hierarchy (XGBoost Gain)

Commute distance and the Monday transit choke interaction dominate the split gain, proving that tardiness is systematically structural rather than purely behavioral.

Feature Importance


3. Confusion Matrix (710 Test Shifts)

Evaluates classification performance at the 0.50 probability threshold, correctly isolating on-time and minor friction from severe operational delays.

Confusion Matrix


4. HR Policy Simulation: 68% Tardiness Reduction Across Departments

Demonstrates the dramatic reduction in tardiness across all five departments when transitioning from a rigid 9:00 AM policy to a 15-minute flexible arrival buffer.

Policy Tardiness Reduction


πŸ’‘ Strategic Recommendations for HR & Operations

  1. Implement a 15-Minute Flexible Grace Window:
    • Over 67.8% of recorded "late" punches occur within 15 minutes of shift start. Adopting a flexible core-hours band (09:15 AM to 09:45 AM arrival with matched checkout) immediately recovers lost morale and administrative overhead while maintaining 8.5-hour productivity.
  2. Stagger Monday Morning Standups Past 10:00 AM:
    • Monday traffic bottlenecks create an odds ratio of $+3.4\times$ severe delay for staff commuting $>18\text{ km}$. Scheduling team standups after 10:00 AM guarantees 100% participation.
  3. Route-Optimized Shuttle or Transit Subsidy for Commuters $>20\text{ km}$:
    • Employees in the $>20\text{ km}$ bracket represent 74% of all severe late hours. Subsidizing transit corridors directly recoups organizational capacity.

πŸ› οΈ Repository Structure

attendance-data-analytics/
β”œβ”€β”€ data/
β”‚   └── attendance_90days_synthetic.csv   # 3,550 calibrated shift records (May–July 2026)
β”œβ”€β”€ figures/                              # Exported publication figures (300 DPI)
β”‚   β”œβ”€β”€ model_roc_curve.png               # Comparison ROC-AUC curves
β”‚   β”œβ”€β”€ model_feature_importance.png      # XGBoost feature importance hierarchy
β”‚   β”œβ”€β”€ model_confusion_matrix.png        # Test split confusion matrix
β”‚   β”œβ”€β”€ policy_tardiness_reduction.png    # Before vs After departmental bar chart
β”‚   β”œβ”€β”€ dept_punctuality_breakdown.png    # Departmental attendance composition
β”‚   β”œβ”€β”€ daily_attendance_trend.png        # 90-day active headcount trend
β”‚   β”œβ”€β”€ checkin_distribution.png          # Arrival timestamp distribution
β”‚   β”œβ”€β”€ day_of_week_comparison.png        # Monday vs weekday tardiness
β”‚   └── commute_distance_vs_tardiness.png # Commute distance scatter correlation
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ late_arrival_pipeline.joblib      # Serialized XGBoost pipeline bundle
β”‚   └── model_metrics.json                # Benchmark cross-validation metrics
β”œβ”€β”€ generate_dataset.py                   # Calibrated synthetic data generator (seed: 42)
β”œβ”€β”€ train_late_arrival_model.py           # ML training pipeline, evaluation & figure export
β”œβ”€β”€ streamlit_app.py                      # Interactive executive HR policy simulator
β”œβ”€β”€ analyze_attendance.py                 # Statistical EDA script
β”œβ”€β”€ attendance_analytics.ipynb            # Interactive Jupyter analysis notebook
β”œβ”€β”€ requirements.txt                      # Project dependencies
β”œβ”€β”€ CHANGELOG_EXPLAINED.md                # Simple interview walkthrough
└── README.md                             # Documentation & architecture guide

πŸš€ How to Run Locally

1. Clone the Repository

git clone https://github.com/prachizala/attendance-data-analytics.git
cd attendance-data-analytics

2. Set Up Virtual Environment & Dependencies

python -m venv .venv

# Windows:
.\.venv\Scripts\activate

# macOS / Linux:
source .venv/bin/activate

pip install -r requirements.txt

3. Run Automated Tests

python -m unittest tests/test_pipeline.py

4. Launch the Interactive Streamlit Simulator

streamlit run streamlit_app.py

5. Retrain Models or Regenerate Data

# Generate synthetic dataset (3,550 shifts, seed 42)
python generate_dataset.py

# Train ML classifiers, benchmark CV metrics, and export figures
python train_late_arrival_model.py

βš™οΈ Environment & Technical Specifications

Parameter Specification Details
Python Runtime Python 3.10 / 3.11 Validated on Python 3.10 & 3.11
Operating Systems Windows 10/11, macOS, Ubuntu 22.04+ Cross-platform compatible
Primary Frameworks Streamlit 1.30+, Scikit-Learn 1.3+, XGBoost 2.0+ Machine learning & web dashboard
Data Processing Pandas 2.x, NumPy 1.24+ Vectorized tabular operations
Visualizations Matplotlib 3.7+, Seaborn 0.12+, Altair 5.0+ Static & interactive charting
Testing Framework unittest (Standard Library) Automated test suite in tests/
CI/CD GitHub Actions Automated build & test matrix on Python 3.10 & 3.11
Containerization Docker (Python 3.11-slim) Standalone deployment on port 8501

πŸ“„ License

This project is open-source under the MIT License.

About

90-day workforce attendance & punctuality data analytics case study (3,550 shifts) using Pandas, Seaborn, and Jupyter.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages