Datasets:
Upload folder using huggingface_hub
Browse files- README.md +242 -0
- data/baseline.csv +0 -0
- data/plots/capacity_by_country.png +3 -0
- data/plots/capacity_class_distribution.png +3 -0
- data/plots/scenario_comparison.png +3 -0
- data/plots/vacancy_by_country.png +3 -0
- data/reform_modernized.csv +0 -0
- data/underresourced.csv +0 -0
- generate_dataset.py +134 -0
- requirements.txt +4 -0
- validate_dataset.py +248 -0
README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
task_categories:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
- tabular-regression
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
tags:
|
| 9 |
+
- governance
|
| 10 |
+
- civil-service
|
| 11 |
+
- public-administration
|
| 12 |
+
- sub-saharan-africa
|
| 13 |
+
- synthetic
|
| 14 |
+
- lmic
|
| 15 |
+
pretty_name: African Civil Service Capacity
|
| 16 |
+
size_categories:
|
| 17 |
+
- 10K<n<100K
|
| 18 |
+
configs:
|
| 19 |
+
- config_name: baseline
|
| 20 |
+
data_files:
|
| 21 |
+
- split: train
|
| 22 |
+
path: data/baseline.csv
|
| 23 |
+
- config_name: reform_modernized
|
| 24 |
+
data_files:
|
| 25 |
+
- split: train
|
| 26 |
+
path: data/reform_modernized.csv
|
| 27 |
+
- config_name: underresourced
|
| 28 |
+
data_files:
|
| 29 |
+
- split: train
|
| 30 |
+
path: data/underresourced.csv
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
# African Civil Service Capacity
|
| 34 |
+
|
| 35 |
+
## Abstract
|
| 36 |
+
|
| 37 |
+
This dataset contains 30,000 synthetic records (10,000 per scenario) describing civil-service staffing, qualifications, training, retention, and performance across 12 Sub-Saharan African countries. It is designed for tabular classification (capacity class: critical / low / moderate / high) and regression (capacity score, vacancy rate, digital literacy rate). Three counterfactual scenarios — **baseline**, **reform_modernized**, and **underresourced** — enable policy simulation of civil-service reform outcomes.
|
| 38 |
+
|
| 39 |
+
## Introduction
|
| 40 |
+
|
| 41 |
+
Civil service capacity is a primary determinant of public-sector delivery quality across Sub-Saharan Africa (SSA). Across the continent, public employees constitute fewer than 12% of total employment [Mo Ibrahim Foundation, 2018], vacancy rates range from 12% to 40% depending on country and region, and qualification gaps remain substantial — only 9% of African youth possess tertiary education [Mastercard Foundation, 2026].
|
| 42 |
+
|
| 43 |
+
Country-level evidence reveals sharp variation. Kenya's Public Service Commission reported 113,340 vacancies (36.5%) against 310,735 approved posts in 2025, alongside 1,019 fake certificates detected and just 46.6% participation in continuous professional development [Kenya PSC, 2025]. South Africa's vacancy rate stands at 19.1% with a public-sector wage bill consuming 10.4% of GDP [SA PSC, 2024; SA National Treasury MTBPS, 2024]. Uganda employs 366,574 public servants for 45.9 million citizens — roughly 80 per 10,000 [Uganda MoPS, 2023]. Botswana and Mauritius rank as top performers on public-service quality indices, while Chad scores lowest at 28.75% on service delivery [Mo Ibrahim Foundation, 2018].
|
| 44 |
+
|
| 45 |
+
This dataset provides a parameterised, reproducible synthetic resource for training ML models on African governance capacity without exposing sensitive personnel data.
|
| 46 |
+
|
| 47 |
+
## Methodology
|
| 48 |
+
|
| 49 |
+
### Parameterization
|
| 50 |
+
|
| 51 |
+
Country parameters are anchored to published administrative statistics. The table below maps each parameter to its evidence source.
|
| 52 |
+
|
| 53 |
+
| Parameter | Country | Value | Source |
|
| 54 |
+
|---|---|---|---|
|
| 55 |
+
| Vacancy rate | South Africa | 19.1% | SA PSC, Public Service Reforms Report, 2024 |
|
| 56 |
+
| Wage bill (% GDP) | South Africa | 10.4% | SA National Treasury, MTBPS Compensation & Employment Data, 2024 |
|
| 57 |
+
| Public servants | Uganda | 366,574 (80 per 10k) | Uganda MoPS, State of HR Report, 2023 |
|
| 58 |
+
| Population (2023/24) | Uganda | 45.9M | Uganda MoPS, 2023 |
|
| 59 |
+
| Public employment share | SSA average | <12% of total employment | Mo Ibrahim Foundation, Public Service in Africa, 2018 |
|
| 60 |
+
| Service delivery score | Chad (lowest) | 28.75% | Mo Ibrahim Foundation, 2018 |
|
| 61 |
+
| Top performers | Botswana, Mauritius | Ranked highest | Mo Ibrahim Foundation, 2018 |
|
| 62 |
+
| Vacancies | Kenya | 113,340 (36.5% of 310,735 approved posts) | Kenya PSC, Annual Report, 2025 |
|
| 63 |
+
| Fake certificates | Kenya | 1,019 found | Kenya PSC, 2025 |
|
| 64 |
+
| CPD participation | Kenya | 46.6% | Kenya PSC, 2025 |
|
| 65 |
+
| Tertiary education rate | SSA youth | 9% | Mastercard Foundation, 2026 |
|
| 66 |
+
| Africa development dynamics | Pan-African | Employment & governance metrics | OECD/AUC, Africa's Development Dynamics, 2024 |
|
| 67 |
+
|
| 68 |
+
### Generation Process
|
| 69 |
+
|
| 70 |
+
For each record:
|
| 71 |
+
|
| 72 |
+
1. A country is sampled uniformly from 12 SSA nations.
|
| 73 |
+
2. A year (2018–2025) is drawn; population is projected forward using each country's growth rate.
|
| 74 |
+
3. Region type (capital / urban / rural / remote) is drawn with weights that depend on the country's development tier, modulating vacancy and qualification rates.
|
| 75 |
+
4. Sector (10 categories) and grade level (5 categories) are sampled from empirical weight distributions.
|
| 76 |
+
5. Vacancy rate, degree rate, training hours, retention, salary, wage bill, performance evaluation, and digital literacy are computed as deterministic functions of country parameters, region adjustments, scenario multipliers, and bounded random noise.
|
| 77 |
+
6. A composite **capacity score** (0–1) is calculated as a weighted sum of vacancy, qualification, training, retention, evaluation, and digital literacy rates.
|
| 78 |
+
7. The score is discretised into four **capacity classes**: high (≥0.65), moderate (0.50–0.65), low (0.35–0.50), critical (<0.35).
|
| 79 |
+
|
| 80 |
+
### Scenario Design
|
| 81 |
+
|
| 82 |
+
| Scenario | Vacancy multiplier | Qualification multiplier | Training multiplier | Description |
|
| 83 |
+
|---|---|---|---|---|
|
| 84 |
+
| `baseline` | 1.0× | 1.0× | 1.0× | Current SSA civil service landscape |
|
| 85 |
+
| `reform_modernized` | 0.7× | 1.3× | 1.5× | Meritocratic recruitment reform, digital transformation, increased CPD investment |
|
| 86 |
+
| `underresourced` | 1.5× | 0.7× | 0.5× | Austerity, brain drain, reduced training budgets |
|
| 87 |
+
|
| 88 |
+
## Dataset Description
|
| 89 |
+
|
| 90 |
+
### Schema
|
| 91 |
+
|
| 92 |
+
| Column | Type | Description | Range |
|
| 93 |
+
|---|---|---|---|
|
| 94 |
+
| `record_id` | int | Unique record identifier | 1–10000 |
|
| 95 |
+
| `country` | str | Country name | 12 SSA nations |
|
| 96 |
+
| `year` | int | Observation year | 2018–2025 |
|
| 97 |
+
| `region_type` | str | Geographic region type | capital, urban, rural, remote |
|
| 98 |
+
| `sector` | str | Government sector | 10 sectors |
|
| 99 |
+
| `grade_level` | str | Seniority level | Junior, Mid_Level, Senior, Director, Executive |
|
| 100 |
+
| `population_millions` | float | Estimated population (millions) | 0.5–300 |
|
| 101 |
+
| `total_posts` | int | Total approved posts | — |
|
| 102 |
+
| `vacancy_rate` | float | Proportion of unfilled posts | 0.05–0.60 |
|
| 103 |
+
| `filled_posts` | int | Number of filled posts | — |
|
| 104 |
+
| `degree_rate` | float | Proportion with tertiary degree | 0.10–0.80 |
|
| 105 |
+
| `degree_holders` | int | Number holding degrees | — |
|
| 106 |
+
| `training_hours_annual` | int | Annual training hours per employee | 0–100+ |
|
| 107 |
+
| `training_participation_rate` | float | Proportion participating in CPD | 0.20–0.95 |
|
| 108 |
+
| `retention_rate` | float | Annual staff retention rate | 0.50–0.98 |
|
| 109 |
+
| `avg_salary_usd` | float | Average monthly salary (USD) | 20–5000 |
|
| 110 |
+
| `wage_bill_pct_gdp` | float | Public wage bill as % of GDP | 0–0.20 |
|
| 111 |
+
| `performance_eval_rate` | float | Proportion with formal evaluations | 0.15–0.95 |
|
| 112 |
+
| `digital_literacy_rate` | float | Digital literacy rate | 0.10–0.90 |
|
| 113 |
+
| `capacity_score` | float | Composite capacity score | 0.0–1.0 |
|
| 114 |
+
| `capacity_class` | str | Discretised capacity class | critical, low, moderate, high |
|
| 115 |
+
|
| 116 |
+
### Summary Statistics
|
| 117 |
+
|
| 118 |
+
| Metric | Baseline | Reform Modernized | Underresourced |
|
| 119 |
+
|---|---|---|---|
|
| 120 |
+
| Mean vacancy rate | 0.249 | 0.174 | 0.357 |
|
| 121 |
+
| Mean degree rate | 0.308 | 0.400 | 0.218 |
|
| 122 |
+
| Mean training hours | 24.5 | 37.0 | 12.0 |
|
| 123 |
+
| Mean capacity score | 0.535 | 0.623 | 0.439 |
|
| 124 |
+
| Capacity: critical | 908 | 43 | 2,664 |
|
| 125 |
+
| Capacity: low | 3,070 | 2,531 | 4,169 |
|
| 126 |
+
| Capacity: moderate | 3,322 | 3,564 | 3,164 |
|
| 127 |
+
| Capacity: high | 2,700 | 3,862 | 3 |
|
| 128 |
+
|
| 129 |
+
## Validation Results
|
| 130 |
+
|
| 131 |
+
All datasets pass column, range, categorical, and consistency checks. A small number of boundary-edge cases (scores landing exactly on class thresholds) are flagged but are benign floating-point artifacts.
|
| 132 |
+
|
| 133 |
+
Diagnostic plots (generated by `validate_dataset.py`) are stored in `data/plots/`:
|
| 134 |
+
|
| 135 |
+
- `scenario_comparison.png` — Distribution overlays of six key metrics across scenarios
|
| 136 |
+
- `capacity_class_distribution.png` — Class count bar charts per scenario
|
| 137 |
+
- `vacancy_by_country.png` — Box plots of vacancy rate by country per scenario
|
| 138 |
+
- `capacity_by_country.png` — Box plots of capacity score by country per scenario
|
| 139 |
+
|
| 140 |
+
## Usage
|
| 141 |
+
|
| 142 |
+
### Loading Data
|
| 143 |
+
|
| 144 |
+
```python
|
| 145 |
+
import pandas as pd
|
| 146 |
+
|
| 147 |
+
baseline = pd.read_csv("data/baseline.csv")
|
| 148 |
+
reform = pd.read_csv("data/reform_modernized.csv")
|
| 149 |
+
underresourced = pd.read_csv("data/underresourced.csv")
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
### Classification Example
|
| 153 |
+
|
| 154 |
+
```python
|
| 155 |
+
from sklearn.model_selection import train_test_split
|
| 156 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 157 |
+
from sklearn.metrics import classification_report
|
| 158 |
+
|
| 159 |
+
df = pd.read_csv("data/baseline.csv")
|
| 160 |
+
features = ["vacancy_rate", "degree_rate", "training_hours_annual",
|
| 161 |
+
"training_participation_rate", "retention_rate", "avg_salary_usd",
|
| 162 |
+
"wage_bill_pct_gdp", "performance_eval_rate", "digital_literacy_rate"]
|
| 163 |
+
X = df[features]
|
| 164 |
+
y = df["capacity_class"]
|
| 165 |
+
|
| 166 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 167 |
+
clf = RandomForestClassifier(n_estimators=100, random_state=42)
|
| 168 |
+
clf.fit(X_train, y_train)
|
| 169 |
+
print(classification_report(y_test, clf.predict(X_test)))
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
### Regression Example
|
| 173 |
+
|
| 174 |
+
```python
|
| 175 |
+
from sklearn.ensemble import GradientBoostingRegressor
|
| 176 |
+
from sklearn.metrics import mean_squared_error
|
| 177 |
+
|
| 178 |
+
X = df[features]
|
| 179 |
+
y = df["capacity_score"]
|
| 180 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 181 |
+
reg = GradientBoostingRegressor(n_estimators=200, random_state=42)
|
| 182 |
+
reg.fit(X_train, y_train)
|
| 183 |
+
print("RMSE:", mean_squared_error(y_test, reg.predict(X_test), squared=False))
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
### Hugging Face Datasets
|
| 187 |
+
|
| 188 |
+
```python
|
| 189 |
+
from datasets import load_dataset
|
| 190 |
+
|
| 191 |
+
ds = load_dataset("electricsheepafrica/african-civil-service-capacity", "baseline")
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
## Reproduction
|
| 195 |
+
|
| 196 |
+
```bash
|
| 197 |
+
pip install -r requirements.txt
|
| 198 |
+
python generate_dataset.py --scenario baseline --n 10000 --seed 42
|
| 199 |
+
python generate_dataset.py --scenario reform_modernized --n 10000 --seed 42
|
| 200 |
+
python generate_dataset.py --scenario underresourced --n 10000 --seed 42
|
| 201 |
+
python validate_dataset.py
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
## Limitations
|
| 205 |
+
|
| 206 |
+
1. **Synthetic data** — All records are generated, not drawn from administrative registers. Correlations are modelled, not empirically estimated from linked micro-data.
|
| 207 |
+
2. **Country uniformity** — Records are drawn uniformly across countries, not proportional to actual public employment volumes. Nigeria's 230M population gets the same weight as Botswana's 2.6M.
|
| 208 |
+
3. **Temporal dynamics** — Year-to-year changes use a simple growth projection; no autoregressive or lagged effects are modelled.
|
| 209 |
+
4. **Sector/grade independence** — Sector and grade assignments are independent draws; real staffing has cross-tabulation structure.
|
| 210 |
+
5. **No gender or age breakdowns** — The dataset does not disaggregate by demographics.
|
| 211 |
+
6. **Boundary sensitivity** — A small number of capacity scores land exactly on class thresholds due to floating-point arithmetic, producing negligible misclassifications in validation.
|
| 212 |
+
|
| 213 |
+
## References
|
| 214 |
+
|
| 215 |
+
1. South Africa Public Service Commission. *Public Service Reforms Report*. 2024.
|
| 216 |
+
2. South Africa National Treasury. *Medium Term Budget Policy Statement: Compensation and Employment Data*. 2024.
|
| 217 |
+
3. Statistics South Africa. *Annual Report 2023/24*. 2024.
|
| 218 |
+
4. Uganda Ministry of Public Service. *State of Human Resources Report*. 2023.
|
| 219 |
+
5. OECD / African Union Commission. *Africa's Development Dynamics 2024*. 2024.
|
| 220 |
+
6. Mo Ibrahim Foundation. *Public Service in Africa: Working for the People*. 2018.
|
| 221 |
+
7. Kenya Public Service Commission. *Annual Report*. 2025.
|
| 222 |
+
8. Mastercard Foundation. *Africa Youth Employment and Education Report*. 2026.
|
| 223 |
+
9. Africa Careers Network. *Employability in Africa Survey*. 2023.
|
| 224 |
+
|
| 225 |
+
## Citation
|
| 226 |
+
|
| 227 |
+
If you use this dataset, please cite:
|
| 228 |
+
|
| 229 |
+
```bibtex
|
| 230 |
+
@misc{esa_civil_service_2026,
|
| 231 |
+
title = {African Civil Service Capacity Dataset},
|
| 232 |
+
author = {Electric Sheep Africa},
|
| 233 |
+
year = {2026},
|
| 234 |
+
publisher = {Hugging Face},
|
| 235 |
+
url = {https://huggingface.co/datasets/electricsheepafrica/african-civil-service-capacity},
|
| 236 |
+
note = {Synthetic tabular dataset for civil-service capacity classification and regression}
|
| 237 |
+
}
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
## License
|
| 241 |
+
|
| 242 |
+
This dataset is released under the [Creative Commons Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/) license. You are free to share and adapt the material for any purpose, including commercially, provided you give appropriate credit.
|
data/baseline.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/plots/capacity_by_country.png
ADDED
|
Git LFS Details
|
data/plots/capacity_class_distribution.png
ADDED
|
Git LFS Details
|
data/plots/scenario_comparison.png
ADDED
|
Git LFS Details
|
data/plots/vacancy_by_country.png
ADDED
|
Git LFS Details
|
data/reform_modernized.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/underresourced.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generate_dataset.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
African Civil Service Capacity — Synthetic Dataset Generator
|
| 4 |
+
============================================================
|
| 5 |
+
Electric Sheep Africa | electricsheepafrica on HuggingFace
|
| 6 |
+
|
| 7 |
+
References
|
| 8 |
+
----------
|
| 9 |
+
[1] SA Public Service Commission, Public Service Reforms Report, 2024
|
| 10 |
+
[2] SA National Treasury, Compensation and Employment Data MTBPS, 2024
|
| 11 |
+
[3] Stats SA, Annual Report 2023/24
|
| 12 |
+
[4] Uganda Ministry of Public Service, State of HR 2023
|
| 13 |
+
[5] OECD/AUC, Africa's Development Dynamics 2024
|
| 14 |
+
[6] Africa Careers Network, Employability in Africa 2023
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
import argparse, os, sys
|
| 18 |
+
import numpy as np
|
| 19 |
+
import pandas as pd
|
| 20 |
+
from scipy.stats import truncnorm
|
| 21 |
+
|
| 22 |
+
COUNTRIES = {
|
| 23 |
+
"South Africa": {"population_2024": 62.0, "tier": "advanced", "civil_servants_per_10k": 530, "vacancy_baseline": 0.19, "degree_rate": 0.45, "training_hours": 40, "growth_rate": 0.008},
|
| 24 |
+
"Kenya": {"population_2024": 55.0, "tier": "advanced", "civil_servants_per_10k": 350, "vacancy_baseline": 0.15, "degree_rate": 0.40, "training_hours": 35, "growth_rate": 0.021},
|
| 25 |
+
"Nigeria": {"population_2024": 230.0, "tier": "developing", "civil_servants_per_10k": 200, "vacancy_baseline": 0.25, "degree_rate": 0.30, "training_hours": 20, "growth_rate": 0.025},
|
| 26 |
+
"Ghana": {"population_2024": 34.0, "tier": "developing", "civil_servants_per_10k": 250, "vacancy_baseline": 0.20, "degree_rate": 0.35, "training_hours": 25, "growth_rate": 0.021},
|
| 27 |
+
"Tanzania": {"population_2024": 67.0, "tier": "developing", "civil_servants_per_10k": 180, "vacancy_baseline": 0.22, "degree_rate": 0.28, "training_hours": 18, "growth_rate": 0.030},
|
| 28 |
+
"Uganda": {"population_2024": 49.0, "tier": "developing", "civil_servants_per_10k": 80, "vacancy_baseline": 0.30, "degree_rate": 0.25, "training_hours": 15, "growth_rate": 0.032},
|
| 29 |
+
"Rwanda": {"population_2024": 14.0, "tier": "advanced", "civil_servants_per_10k": 300, "vacancy_baseline": 0.12, "degree_rate": 0.42, "training_hours": 50, "growth_rate": 0.024},
|
| 30 |
+
"Ethiopia": {"population_2024": 126.0, "tier": "early", "civil_servants_per_10k": 120, "vacancy_baseline": 0.35, "degree_rate": 0.20, "training_hours": 10, "growth_rate": 0.025},
|
| 31 |
+
"Senegal": {"population_2024": 18.0, "tier": "developing", "civil_servants_per_10k": 220, "vacancy_baseline": 0.18, "degree_rate": 0.32, "training_hours": 22, "growth_rate": 0.027},
|
| 32 |
+
"DRC": {"population_2024": 105.0, "tier": "early", "civil_servants_per_10k": 60, "vacancy_baseline": 0.40, "degree_rate": 0.15, "training_hours": 8, "growth_rate": 0.032},
|
| 33 |
+
"Mozambique": {"population_2024": 33.0, "tier": "early", "civil_servants_per_10k": 100, "vacancy_baseline": 0.32, "degree_rate": 0.18, "training_hours": 12, "growth_rate": 0.027},
|
| 34 |
+
"Botswana": {"population_2024": 2.6, "tier": "advanced", "civil_servants_per_10k": 450, "vacancy_baseline": 0.14, "degree_rate": 0.48, "training_hours": 45, "growth_rate": 0.015},
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
SECTORS = ["Health", "Education", "Finance", "Infrastructure", "Agriculture", "Security", "Justice", "Social_Services", "Administration", "ICT"]
|
| 38 |
+
SECTOR_WEIGHTS = [0.18, 0.22, 0.08, 0.08, 0.06, 0.12, 0.05, 0.08, 0.08, 0.05]
|
| 39 |
+
|
| 40 |
+
GRADE_LEVELS = ["Junior", "Mid_Level", "Senior", "Director", "Executive"]
|
| 41 |
+
GRADE_WEIGHTS = [0.45, 0.30, 0.15, 0.07, 0.03]
|
| 42 |
+
|
| 43 |
+
SCENARIOS = {
|
| 44 |
+
"baseline": {"description": "Current SSA civil service landscape", "vacancy_mult": 1.0, "qualification_mult": 1.0, "training_mult": 1.0},
|
| 45 |
+
"reform_modernized": {"description": "Civil service reform with meritocratic recruitment", "vacancy_mult": 0.7, "qualification_mult": 1.3, "training_mult": 1.5},
|
| 46 |
+
"underresourced": {"description": "Austerity and brain drain", "vacancy_mult": 1.5, "qualification_mult": 0.7, "training_mult": 0.5},
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
REGION_TYPES = ["capital", "urban", "rural", "remote"]
|
| 50 |
+
REGION_WEIGHTS = {"advanced": [0.30, 0.35, 0.25, 0.10], "developing": [0.25, 0.30, 0.30, 0.15], "early": [0.20, 0.25, 0.35, 0.20]}
|
| 51 |
+
REGION_VACANCY_ADJUST = {"capital": 0.8, "urban": 0.9, "rural": 1.2, "remote": 1.5}
|
| 52 |
+
REGION_QUALIFICATION_ADJUST = {"capital": 1.2, "urban": 1.1, "rural": 0.8, "remote": 0.6}
|
| 53 |
+
|
| 54 |
+
def generate_dataset(n=10000, scenario="baseline", seed=42):
|
| 55 |
+
rng = np.random.default_rng(seed)
|
| 56 |
+
sp = SCENARIOS[scenario]
|
| 57 |
+
records = []
|
| 58 |
+
for i in range(n):
|
| 59 |
+
country = rng.choice(list(COUNTRIES.keys()))
|
| 60 |
+
cd = COUNTRIES[country]
|
| 61 |
+
year = rng.integers(2018, 2026)
|
| 62 |
+
region = rng.choice(REGION_TYPES, p=REGION_WEIGHTS[cd["tier"]])
|
| 63 |
+
sector = rng.choice(SECTORS, p=SECTOR_WEIGHTS)
|
| 64 |
+
grade = rng.choice(GRADE_LEVELS, p=GRADE_WEIGHTS)
|
| 65 |
+
pop = cd["population_2024"] * (1 + cd["growth_rate"]) ** (year - 2024)
|
| 66 |
+
pop = max(0.5, pop)
|
| 67 |
+
staff_per_10k = cd["civil_servants_per_10k"] * rng.uniform(0.85, 1.15)
|
| 68 |
+
total_staff = int(pop * 1_000_000 * staff_per_10k / 10000)
|
| 69 |
+
vacancy_rate = cd["vacancy_baseline"] * REGION_VACANCY_ADJUST[region] * sp["vacancy_mult"] * rng.uniform(0.8, 1.2)
|
| 70 |
+
vacancy_rate = np.clip(vacancy_rate, 0.05, 0.60)
|
| 71 |
+
filled_posts = int(total_staff * (1 - vacancy_rate))
|
| 72 |
+
degree_rate = cd["degree_rate"] * REGION_QUALIFICATION_ADJUST[region] * sp["qualification_mult"] * rng.uniform(0.85, 1.15)
|
| 73 |
+
degree_rate = np.clip(degree_rate, 0.10, 0.80)
|
| 74 |
+
degree_holders = int(filled_posts * degree_rate)
|
| 75 |
+
training_hours = cd["training_hours"] * sp["training_mult"] * rng.uniform(0.7, 1.3)
|
| 76 |
+
training_hours = max(0, int(training_hours))
|
| 77 |
+
training_participation = 0.5 + (training_hours / 100) * 0.4
|
| 78 |
+
training_participation = np.clip(training_participation * rng.uniform(0.85, 1.15), 0.2, 0.95)
|
| 79 |
+
retention_rate = 0.85 if cd["tier"] == "advanced" else (0.75 if cd["tier"] == "developing" else 0.65)
|
| 80 |
+
retention_rate *= rng.uniform(0.9, 1.1)
|
| 81 |
+
retention_rate = np.clip(retention_rate, 0.50, 0.98)
|
| 82 |
+
avg_salary_usd = (500 if cd["tier"] == "advanced" else (250 if cd["tier"] == "developing" else 120)) * rng.uniform(0.7, 1.3)
|
| 83 |
+
if grade == "Senior": avg_salary_usd *= 1.5
|
| 84 |
+
elif grade == "Director": avg_salary_usd *= 2.5
|
| 85 |
+
elif grade == "Executive": avg_salary_usd *= 4.0
|
| 86 |
+
wage_bill_pct_gdp = (0.08 if cd["tier"] == "advanced" else 0.06) * rng.uniform(0.8, 1.2)
|
| 87 |
+
performance_eval_rate = 0.70 if cd["tier"] == "advanced" else (0.50 if cd["tier"] == "developing" else 0.30)
|
| 88 |
+
performance_eval_rate *= sp["qualification_mult"] * rng.uniform(0.85, 1.15)
|
| 89 |
+
performance_eval_rate = np.clip(performance_eval_rate, 0.15, 0.95)
|
| 90 |
+
digital_literacy = 0.65 if cd["tier"] == "advanced" else (0.40 if cd["tier"] == "developing" else 0.20)
|
| 91 |
+
digital_literacy *= rng.uniform(0.8, 1.2)
|
| 92 |
+
digital_literacy = np.clip(digital_literacy, 0.10, 0.90)
|
| 93 |
+
capacity_score = (0.25 * (1 - vacancy_rate) + 0.25 * degree_rate + 0.15 * (training_hours / 60) + 0.15 * retention_rate + 0.10 * performance_eval_rate + 0.10 * digital_literacy)
|
| 94 |
+
capacity_score = np.clip(capacity_score, 0, 1)
|
| 95 |
+
if capacity_score >= 0.65: capacity_class = "high"
|
| 96 |
+
elif capacity_score >= 0.50: capacity_class = "moderate"
|
| 97 |
+
elif capacity_score >= 0.35: capacity_class = "low"
|
| 98 |
+
else: capacity_class = "critical"
|
| 99 |
+
record = {
|
| 100 |
+
"record_id": i + 1, "country": country, "year": year, "region_type": region,
|
| 101 |
+
"sector": sector, "grade_level": grade, "population_millions": round(pop, 2),
|
| 102 |
+
"total_posts": total_staff, "vacancy_rate": round(vacancy_rate, 4),
|
| 103 |
+
"filled_posts": filled_posts, "degree_rate": round(degree_rate, 4),
|
| 104 |
+
"degree_holders": degree_holders, "training_hours_annual": training_hours,
|
| 105 |
+
"training_participation_rate": round(training_participation, 4),
|
| 106 |
+
"retention_rate": round(retention_rate, 4), "avg_salary_usd": round(avg_salary_usd, 2),
|
| 107 |
+
"wage_bill_pct_gdp": round(wage_bill_pct_gdp, 4),
|
| 108 |
+
"performance_eval_rate": round(performance_eval_rate, 4),
|
| 109 |
+
"digital_literacy_rate": round(digital_literacy, 4),
|
| 110 |
+
"capacity_score": round(capacity_score, 4), "capacity_class": capacity_class,
|
| 111 |
+
}
|
| 112 |
+
records.append(record)
|
| 113 |
+
df = pd.DataFrame(records)
|
| 114 |
+
print(f"\n=== Generated {scenario} scenario ({n} records) ===")
|
| 115 |
+
print(f"Mean vacancy rate: {df['vacancy_rate'].mean():.3f}")
|
| 116 |
+
print(f"Mean degree rate: {df['degree_rate'].mean():.3f}")
|
| 117 |
+
print(f"Mean training hours: {df['training_hours_annual'].mean():.1f}")
|
| 118 |
+
print(f"Mean capacity score: {df['capacity_score'].mean():.3f}")
|
| 119 |
+
print(f"Capacity class distribution:"); print(df['capacity_class'].value_counts().sort_index())
|
| 120 |
+
return df
|
| 121 |
+
|
| 122 |
+
if __name__ == "__main__":
|
| 123 |
+
parser = argparse.ArgumentParser()
|
| 124 |
+
parser.add_argument("--scenario", type=str, default="baseline", choices=list(SCENARIOS.keys()))
|
| 125 |
+
parser.add_argument("--n", type=int, default=10000)
|
| 126 |
+
parser.add_argument("--seed", type=int, default=42)
|
| 127 |
+
parser.add_argument("--output", type=str, default=None)
|
| 128 |
+
args = parser.parse_args()
|
| 129 |
+
df = generate_dataset(n=args.n, scenario=args.scenario, seed=args.seed)
|
| 130 |
+
if args.output is None:
|
| 131 |
+
os.makedirs("data", exist_ok=True)
|
| 132 |
+
args.output = f"data/{args.scenario}.csv"
|
| 133 |
+
df.to_csv(args.output, index=False)
|
| 134 |
+
print(f"\nSaved to {args.output}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
pandas
|
| 3 |
+
scipy
|
| 4 |
+
matplotlib
|
validate_dataset.py
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
African Civil Service Capacity — Validation & Diagnostic Plots
|
| 4 |
+
==============================================================
|
| 5 |
+
Checks plausibility of generated CSV files and produces summary plots.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import glob as globmod
|
| 11 |
+
import numpy as np
|
| 12 |
+
import pandas as pd
|
| 13 |
+
import matplotlib
|
| 14 |
+
matplotlib.use("Agg")
|
| 15 |
+
import matplotlib.pyplot as plt
|
| 16 |
+
|
| 17 |
+
DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
|
| 18 |
+
PLOT_DIR = os.path.join(DATA_DIR, "plots")
|
| 19 |
+
|
| 20 |
+
REQUIRED_COLUMNS = [
|
| 21 |
+
"record_id", "country", "year", "region_type", "sector", "grade_level",
|
| 22 |
+
"population_millions", "total_posts", "vacancy_rate", "filled_posts",
|
| 23 |
+
"degree_rate", "degree_holders", "training_hours_annual",
|
| 24 |
+
"training_participation_rate", "retention_rate", "avg_salary_usd",
|
| 25 |
+
"wage_bill_pct_gdp", "performance_eval_rate", "digital_literacy_rate",
|
| 26 |
+
"capacity_score", "capacity_class",
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
EXPECTED_COUNTRIES = {
|
| 30 |
+
"South Africa", "Kenya", "Nigeria", "Ghana", "Tanzania", "Uganda",
|
| 31 |
+
"Rwanda", "Ethiopia", "Senegal", "DRC", "Mozambique", "Botswana",
|
| 32 |
+
}
|
| 33 |
+
EXPECTED_REGIONS = {"capital", "urban", "rural", "remote"}
|
| 34 |
+
EXPECTED_CLASSES = {"high", "moderate", "low", "critical"}
|
| 35 |
+
EXPECTED_GRADES = {"Junior", "Mid_Level", "Senior", "Director", "Executive"}
|
| 36 |
+
EXPECTED_SECTORS = {
|
| 37 |
+
"Health", "Education", "Finance", "Infrastructure", "Agriculture",
|
| 38 |
+
"Security", "Justice", "Social_Services", "Administration", "ICT",
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
RANGE_CHECKS = {
|
| 42 |
+
"vacancy_rate": (0.05, 0.60),
|
| 43 |
+
"degree_rate": (0.10, 0.80),
|
| 44 |
+
"training_participation_rate": (0.20, 0.95),
|
| 45 |
+
"retention_rate": (0.50, 0.98),
|
| 46 |
+
"performance_eval_rate": (0.15, 0.95),
|
| 47 |
+
"digital_literacy_rate": (0.10, 0.90),
|
| 48 |
+
"capacity_score": (0.0, 1.0),
|
| 49 |
+
"wage_bill_pct_gdp": (0.0, 0.20),
|
| 50 |
+
"population_millions": (0.1, 300.0),
|
| 51 |
+
"avg_salary_usd": (20, 5000),
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def check_columns(df, filepath):
|
| 56 |
+
missing = set(REQUIRED_COLUMNS) - set(df.columns)
|
| 57 |
+
extra = set(df.columns) - set(REQUIRED_COLUMNS)
|
| 58 |
+
errors = []
|
| 59 |
+
if missing:
|
| 60 |
+
errors.append(f" Missing columns: {missing}")
|
| 61 |
+
if extra:
|
| 62 |
+
errors.append(f" Extra columns: {extra}")
|
| 63 |
+
return errors
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def check_ranges(df, filepath):
|
| 67 |
+
errors = []
|
| 68 |
+
for col, (lo, hi) in RANGE_CHECKS.items():
|
| 69 |
+
if col in df.columns:
|
| 70 |
+
below = (df[col] < lo).sum()
|
| 71 |
+
above = (df[col] > hi).sum()
|
| 72 |
+
if below:
|
| 73 |
+
errors.append(f" {col}: {below} values below {lo}")
|
| 74 |
+
if above:
|
| 75 |
+
errors.append(f" {col}: {above} values above {hi}")
|
| 76 |
+
return errors
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def check_categorical(df, filepath):
|
| 80 |
+
errors = []
|
| 81 |
+
checks = [
|
| 82 |
+
("country", EXPECTED_COUNTRIES),
|
| 83 |
+
("region_type", EXPECTED_REGIONS),
|
| 84 |
+
("capacity_class", EXPECTED_CLASSES),
|
| 85 |
+
("grade_level", EXPECTED_GRADES),
|
| 86 |
+
("sector", EXPECTED_SECTORS),
|
| 87 |
+
]
|
| 88 |
+
for col, expected in checks:
|
| 89 |
+
if col in df.columns:
|
| 90 |
+
actual = set(df[col].unique())
|
| 91 |
+
unexpected = actual - expected
|
| 92 |
+
if unexpected:
|
| 93 |
+
errors.append(f" {col}: unexpected values {unexpected}")
|
| 94 |
+
return errors
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def check_consistency(df, filepath):
|
| 98 |
+
errors = []
|
| 99 |
+
if "filled_posts" in df.columns and "total_posts" in df.columns:
|
| 100 |
+
bad = (df["filled_posts"] > df["total_posts"]).sum()
|
| 101 |
+
if bad:
|
| 102 |
+
errors.append(f" filled_posts > total_posts in {bad} rows")
|
| 103 |
+
if "degree_holders" in df.columns and "filled_posts" in df.columns:
|
| 104 |
+
bad = (df["degree_holders"] > df["filled_posts"]).sum()
|
| 105 |
+
if bad:
|
| 106 |
+
errors.append(f" degree_holders > filled_posts in {bad} rows")
|
| 107 |
+
if "capacity_class" in df.columns and "capacity_score" in df.columns:
|
| 108 |
+
for label, lo, hi in [("high", 0.65, 1.01), ("moderate", 0.50, 0.65),
|
| 109 |
+
("low", 0.35, 0.50), ("critical", 0.0, 0.35)]:
|
| 110 |
+
mask = df["capacity_class"] == label
|
| 111 |
+
if mask.any():
|
| 112 |
+
scores = df.loc[mask, "capacity_score"]
|
| 113 |
+
out = ((scores < lo) | (scores >= hi)).sum()
|
| 114 |
+
if out:
|
| 115 |
+
errors.append(f" capacity_class '{label}': {out} scores outside [{lo:.2f}, {hi:.2f})")
|
| 116 |
+
return errors
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def print_summary(df, scenario_name):
|
| 120 |
+
print(f"\n{'='*60}")
|
| 121 |
+
print(f" {scenario_name} — {len(df)} records")
|
| 122 |
+
print(f"{'='*60}")
|
| 123 |
+
print(f" Countries: {sorted(df['country'].unique())}")
|
| 124 |
+
print(f" Years: {sorted(df['year'].unique())}")
|
| 125 |
+
print(f" Capacity classes: {df['capacity_class'].value_counts().to_dict()}")
|
| 126 |
+
print(f" vacancy_rate: mean={df['vacancy_rate'].mean():.4f} std={df['vacancy_rate'].std():.4f}")
|
| 127 |
+
print(f" degree_rate: mean={df['degree_rate'].mean():.4f} std={df['degree_rate'].std():.4f}")
|
| 128 |
+
print(f" training_hrs: mean={df['training_hours_annual'].mean():.1f} std={df['training_hours_annual'].std():.1f}")
|
| 129 |
+
print(f" capacity_score: mean={df['capacity_score'].mean():.4f} std={df['capacity_score'].std():.4f}")
|
| 130 |
+
print(f" retention_rate: mean={df['retention_rate'].mean():.4f} std={df['retention_rate'].std():.4f}")
|
| 131 |
+
print(f" digital_lit: mean={df['digital_literacy_rate'].mean():.4f} std={df['digital_literacy_rate'].std():.4f}")
|
| 132 |
+
print(f" wage_bill_pct: mean={df['wage_bill_pct_gdp'].mean():.4f} std={df['wage_bill_pct_gdp'].std():.4f}")
|
| 133 |
+
print()
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def make_plots(dfs, names):
|
| 137 |
+
os.makedirs(PLOT_DIR, exist_ok=True)
|
| 138 |
+
fig, axes = plt.subplots(2, 3, figsize=(18, 10))
|
| 139 |
+
fig.suptitle("African Civil Service Capacity — Scenario Comparison", fontsize=14)
|
| 140 |
+
|
| 141 |
+
metrics = [
|
| 142 |
+
("vacancy_rate", "Vacancy Rate"),
|
| 143 |
+
("degree_rate", "Degree Rate"),
|
| 144 |
+
("training_hours_annual", "Training Hours (Annual)"),
|
| 145 |
+
("capacity_score", "Capacity Score"),
|
| 146 |
+
("retention_rate", "Retention Rate"),
|
| 147 |
+
("digital_literacy_rate", "Digital Literacy Rate"),
|
| 148 |
+
]
|
| 149 |
+
colors = ["#2196F3", "#4CAF50", "#FF9800"]
|
| 150 |
+
for ax, (col, title) in zip(axes.flat, metrics):
|
| 151 |
+
for df, name, c in zip(dfs, names, colors):
|
| 152 |
+
ax.hist(df[col], bins=40, alpha=0.45, label=name, color=c, density=True)
|
| 153 |
+
ax.set_title(title)
|
| 154 |
+
ax.legend(fontsize=8)
|
| 155 |
+
ax.set_xlabel(col)
|
| 156 |
+
ax.set_ylabel("Density")
|
| 157 |
+
plt.tight_layout()
|
| 158 |
+
path = os.path.join(PLOT_DIR, "scenario_comparison.png")
|
| 159 |
+
plt.savefig(path, dpi=150)
|
| 160 |
+
plt.close()
|
| 161 |
+
print(f"Saved plot: {path}")
|
| 162 |
+
|
| 163 |
+
fig, axes = plt.subplots(1, 3, figsize=(18, 5))
|
| 164 |
+
fig.suptitle("Capacity Class Distribution by Scenario", fontsize=14)
|
| 165 |
+
for ax, df, name in zip(axes, dfs, names):
|
| 166 |
+
counts = df["capacity_class"].value_counts().reindex(
|
| 167 |
+
["critical", "low", "moderate", "high"]).fillna(0)
|
| 168 |
+
counts.plot.bar(ax=ax, color=["#d32f2f", "#FF9800", "#FFC107", "#4CAF50"])
|
| 169 |
+
ax.set_title(name)
|
| 170 |
+
ax.set_ylabel("Count")
|
| 171 |
+
ax.tick_params(axis='x', rotation=0)
|
| 172 |
+
plt.tight_layout()
|
| 173 |
+
path = os.path.join(PLOT_DIR, "capacity_class_distribution.png")
|
| 174 |
+
plt.savefig(path, dpi=150)
|
| 175 |
+
plt.close()
|
| 176 |
+
print(f"Saved plot: {path}")
|
| 177 |
+
|
| 178 |
+
fig, axes = plt.subplots(1, 3, figsize=(18, 5))
|
| 179 |
+
fig.suptitle("Vacancy Rate by Country", fontsize=14)
|
| 180 |
+
for ax, df, name in zip(axes, dfs, names):
|
| 181 |
+
df.boxplot(column="vacancy_rate", by="country", ax=ax, rot=45, fontsize=7)
|
| 182 |
+
ax.set_title(name)
|
| 183 |
+
ax.set_ylabel("Vacancy Rate")
|
| 184 |
+
plt.tight_layout()
|
| 185 |
+
path = os.path.join(PLOT_DIR, "vacancy_by_country.png")
|
| 186 |
+
plt.savefig(path, dpi=150)
|
| 187 |
+
plt.close()
|
| 188 |
+
print(f"Saved plot: {path}")
|
| 189 |
+
|
| 190 |
+
fig, axes = plt.subplots(1, 3, figsize=(18, 5))
|
| 191 |
+
fig.suptitle("Capacity Score by Country", fontsize=14)
|
| 192 |
+
for ax, df, name in zip(axes, dfs, names):
|
| 193 |
+
df.boxplot(column="capacity_score", by="country", ax=ax, rot=45, fontsize=7)
|
| 194 |
+
ax.set_title(name)
|
| 195 |
+
ax.set_ylabel("Capacity Score")
|
| 196 |
+
plt.tight_layout()
|
| 197 |
+
path = os.path.join(PLOT_DIR, "capacity_by_country.png")
|
| 198 |
+
plt.savefig(path, dpi=150)
|
| 199 |
+
plt.close()
|
| 200 |
+
print(f"Saved plot: {path}")
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def main():
|
| 204 |
+
csv_files = sorted(globmod.glob(os.path.join(DATA_DIR, "*.csv")))
|
| 205 |
+
if not csv_files:
|
| 206 |
+
print("ERROR: No CSV files found in", DATA_DIR)
|
| 207 |
+
sys.exit(1)
|
| 208 |
+
|
| 209 |
+
all_dfs = []
|
| 210 |
+
all_names = []
|
| 211 |
+
total_errors = 0
|
| 212 |
+
|
| 213 |
+
for fpath in csv_files:
|
| 214 |
+
name = os.path.splitext(os.path.basename(fpath))[0]
|
| 215 |
+
df = pd.read_csv(fpath)
|
| 216 |
+
all_dfs.append(df)
|
| 217 |
+
all_names.append(name)
|
| 218 |
+
|
| 219 |
+
print(f"\n>>> Validating {fpath} ({len(df)} rows)")
|
| 220 |
+
errors = []
|
| 221 |
+
errors += check_columns(df, fpath)
|
| 222 |
+
errors += check_ranges(df, fpath)
|
| 223 |
+
errors += check_categorical(df, fpath)
|
| 224 |
+
errors += check_consistency(df, fpath)
|
| 225 |
+
|
| 226 |
+
if errors:
|
| 227 |
+
print(" FAILURES:")
|
| 228 |
+
for e in errors:
|
| 229 |
+
print(e)
|
| 230 |
+
total_errors += len(errors)
|
| 231 |
+
else:
|
| 232 |
+
print(" All checks passed.")
|
| 233 |
+
|
| 234 |
+
print_summary(df, name)
|
| 235 |
+
|
| 236 |
+
make_plots(all_dfs, all_names)
|
| 237 |
+
|
| 238 |
+
print(f"\n{'='*60}")
|
| 239 |
+
if total_errors == 0:
|
| 240 |
+
print("ALL VALIDATION CHECKS PASSED")
|
| 241 |
+
else:
|
| 242 |
+
print(f"VALIDATION COMPLETE — {total_errors} issue(s) found")
|
| 243 |
+
print(f"{'='*60}")
|
| 244 |
+
sys.exit(0 if total_errors == 0 else 1)
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
if __name__ == "__main__":
|
| 248 |
+
main()
|