# farhann198/predicting-employee-attrition architecture

> Architecture diagram of the GitHub repository farhann198/predicting-employee-attrition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/farhann198/predicting-employee-attrition
- Repository: https://github.com/farhann198/predicting-employee-attrition

## Overview

#### Purpose and Execution

This is a notebook-driven Python machine-learning study for predicting employee attrition from IBM HR Analytics data. Its sole execution entry point is `attrition-prediction.ipynb`; there is no deployed service, API, package, or application runtime. The notebook consumes `WA_Fn-UseC_-HR-Employee-Attrition.csv` and installs dependencies from `requirement.txt`.

#### Data Boundary

`WA_Fn-UseC_-HR-Employee-Attrition.csv` is the local source-of-truth dataset: 1,470 employee records with HR, demographic, compensation, satisfaction, and career attributes. The supervised classification target is the `Attrition` Yes/No field. Data processing and outputs are managed interactively inside `attrition-prediction.ipynb`, rather than persisted as a reusable feature store or model artifact.

#### Preparation and Feature Pipeline

The notebook’s first major stage performs cleaning, exploratory analysis, and feature preparation in `attrition-prediction.ipynb`. It converts categorical variables through label and one-hot encoding, constructs model-ready numerical features, and separates predictors from the attrition target. This is the central transformation boundary between raw HR records and learning inputs.

#### Training and Imbalance Handling

Prepared data is split into train/test partitions in `attrition-prediction.ipynb`. Class imbalance is addressed with SMOTE-Tomek from imbalanced-learn, intended to resample the training data before fitting. The workflow compares Logistic Regression, Decision Tree, Random Forest, SVM, KNN, Gradient Boosting, and XGBoost models within the notebook.

#### Optimization and Model Selection

XGBoost is the reported best model. `attrition-prediction.ipynb` uses Optuna for Bayesian hyperparameter optimization, described as 100 trials, then evaluates trained candidates using classification metrics including accuracy and ROC-AUC. Model selection remains an interactive notebook result; no serialized trained model or inference interface exists in the repository.

#### Interpretation and Survival Analysis

The notebook adds two analytical paths after predictive modeling. SHAP explains feature-level influence for attrition predictions, with job satisfaction, income, tenure, overtime, and age identified as major contributors. Lifelines Cox proportional-hazards analysis estimates time-to-attrition and reports concordance performance. Both analyses are downstream of the processed employee data and complement—not replace—the binary classifier.

#### Runtime and External Dependencies

The required runtime is Python in Jupyter, launched manually. Core external libraries include pandas/NumPy for tabular processing, scikit-learn and XGBoost for models, Optuna for tuning, imbalanced-learn for SMOTE-Tomek, SHAP for explainability, and Lifelines for survival modeling; dependencies are declared in `requirement.txt`. No cloud infrastructure, database, remote inference endpoint, experiment tracker, container, or UI is currently implemented.

Main entry points: [`attrition-prediction.ipynb`](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb) (Cleaning & feature preparation), [`requirement.txt`](https://github.com/farhann198/predicting-employee-attrition/blob/main/requirement.txt) (Python dependencies), [`WA_Fn-UseC_-HR-Employee-Attrition.csv`](https://github.com/farhann198/predicting-employee-attrition/blob/main/WA_Fn-UseC_-HR-Employee-Attrition.csv) (IBM HR employee data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Notebook Runtime"]
  node_dependencies["Python dependencies<br/>requirements<br/>[requirement.txt]"]
  node_notebook["Attrition study notebook<br/>Jupyter notebook"]
end

subgraph group_predictive["Attrition Modeling"]
  node_preparation["Cleaning &amp; feature preparation<br/>notebook stage"]
  node_split["Train/test split<br/>notebook stage"]
  node_resampling["SMOTE-Tomek resampling<br/>imbalance handling"]
  node_candidate_models["Candidate classifiers<br/>model comparison"]
  node_optuna["Optuna tuning<br/>hyperparameter optimization"]
  node_xgboost{{"Selected XGBoost model<br/>binary classifier"}}
  node_evaluation["Classification evaluation<br/>metrics"]
end

subgraph group_analysis["Downstream Analysis"]
  node_shap["SHAP explanations<br/>explainability analysis"]
  node_cox["Cox survival analysis<br/>survival model"]
end

node_dataset[("IBM HR employee data<br/>CSV dataset")]

node_dependencies -.->|"provides libraries"| node_notebook
node_dataset -->|"loaded by"| node_notebook
node_notebook -->|"executes"| node_preparation
node_preparation -->|"model-ready features"| node_split
node_split -->|"training partition"| node_resampling
node_resampling -->|"balanced training data"| node_candidate_models
node_candidate_models -->|"selects XGBoost for tuning"| node_optuna
node_optuna -->|"best hyperparameters"| node_xgboost
node_candidate_models -->|"candidate predictions"| node_evaluation
node_xgboost -->|"selected-model predictions"| node_evaluation
node_xgboost -->|"prediction explanations"| node_shap
node_preparation -->|"processed employee data"| node_cox

click node_dependencies "https://github.com/farhann198/predicting-employee-attrition/blob/main/requirement.txt"
click node_notebook "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_dataset "https://github.com/farhann198/predicting-employee-attrition/blob/main/WA_Fn-UseC_-HR-Employee-Attrition.csv"
click node_preparation "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_split "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_resampling "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_candidate_models "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_optuna "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_xgboost "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_evaluation "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_shap "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"
click node_cox "https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dependencies,node_notebook toneBlue
class node_preparation,node_split,node_resampling,node_candidate_models,node_optuna,node_xgboost,node_evaluation toneAmber
class node_shap,node_cox toneMint
class node_dataset toneNeutral
```

## Components

### Notebook Runtime

Manual Python/Jupyter execution.

- [Python dependencies](https://github.com/farhann198/predicting-employee-attrition/blob/main/requirement.txt): requirements · Notebook libraries are declared here. · `requirement.txt`
- [Attrition study notebook](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): Jupyter notebook · The repository's sole execution entry point. · `attrition-prediction.ipynb`

### Attrition Modeling

- [Cleaning & feature preparation](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): notebook stage · Encodes categorical fields and separates predictors from Attrition. · `attrition-prediction.ipynb`
- [Train/test split](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): notebook stage · `attrition-prediction.ipynb`
- [SMOTE-Tomek resampling](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): imbalance handling · Resamples training data before fitting. · `attrition-prediction.ipynb`
- [Candidate classifiers](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): model comparison · Compares linear, tree, SVM, KNN, boosting, and XGBoost models. · `attrition-prediction.ipynb`
- [Optuna tuning](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): hyperparameter optimization · Runs Bayesian optimization for XGBoost. · `attrition-prediction.ipynb`
- [Selected XGBoost model](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): binary classifier · Reported best attrition model; retained interactively only. · `attrition-prediction.ipynb`
- [Classification evaluation](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): metrics · Evaluates candidates with accuracy and ROC-AUC. · `attrition-prediction.ipynb`

### Downstream Analysis

- [SHAP explanations](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): explainability analysis · Explains feature-level influence on attrition predictions. · `attrition-prediction.ipynb`
- [Cox survival analysis](https://github.com/farhann198/predicting-employee-attrition/blob/main/attrition-prediction.ipynb): survival model · Estimates time-to-attrition and concordance. · `attrition-prediction.ipynb`

### Other components

- [IBM HR employee data](https://github.com/farhann198/predicting-employee-attrition/blob/main/WA_Fn-UseC_-HR-Employee-Attrition.csv): CSV dataset · Local source of truth; Attrition is the Yes/No target. · `WA_Fn-UseC_-HR-Employee-Attrition.csv`

## Connections

- Python dependencies → Attrition study notebook: provides libraries
- IBM HR employee data → Attrition study notebook: loaded by
- Attrition study notebook → Cleaning & feature preparation: executes
- Cleaning & feature preparation → Train/test split: model-ready features
- Train/test split → SMOTE-Tomek resampling: training partition
- SMOTE-Tomek resampling → Candidate classifiers: balanced training data
- Candidate classifiers → Optuna tuning: selects XGBoost for tuning
- Optuna tuning → Selected XGBoost model: best hyperparameters
- Candidate classifiers → Classification evaluation: candidate predictions
- Selected XGBoost model → Classification evaluation: selected-model predictions
- Selected XGBoost model → SHAP explanations: prediction explanations
- Cleaning & feature preparation → Cox survival analysis: processed employee data
