Kossisoroyce commited on
Commit
8a98d6d
·
verified ·
1 Parent(s): ef2a6ac

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ task_categories:
4
+ - tabular-classification
5
+ - tabular-regression
6
+ language:
7
+ - en
8
+ tags:
9
+ - financial-inclusion
10
+ - fintech
11
+ - africa
12
+ - synthetic-data
13
+ - sub-saharan-africa
14
+ - credit-access
15
+ size_categories:
16
+ - 10K<n<100K
17
+ ---
18
+
19
+ # Credit Access Patterns in Africa
20
+
21
+ Synthetic dataset modeling credit access, approval, and repayment patterns across 15 Sub-Saharan African countries from 2018-2025.
22
+
23
+ ## Dataset Description
24
+
25
+ This dataset simulates individual-level credit seeking behavior, application outcomes, and repayment patterns. It captures the spectrum of formal and informal credit sources, from commercial banks to family loans, and the barriers faced by those seeking credit.
26
+
27
+ ### Key Statistics
28
+
29
+ | Metric | Value |
30
+ |--------|-------|
31
+ | Total Records | 15,000 |
32
+ | Countries | 15 |
33
+ | Time Period | 2018-2025 |
34
+ | Credit Need Rate | ~40% |
35
+ | Formal Credit Access | ~15% |
36
+ | Approval Rate (formal) | ~45% |
37
+ | Approval Rate (informal) | ~75% |
38
+ | Avg Loan Amount | $500-2,000 USD |
39
+ | Interest Rate Range | 5-120% APR |
40
+
41
+ ### Coverage by Scenario
42
+
43
+ - `low_burden`: 4,000 records
44
+ - `moderate_burden`: 5,000 records
45
+ - `high_burden`: 6,000 records
46
+
47
+ ## Column Descriptions
48
+
49
+ | Column | Type | Description |
50
+ |--------|------|-------------|
51
+ | country | string | One of 15 SSA countries |
52
+ | year | int | Year (2018-2025) |
53
+ | urban_rural | string | Urban or rural location |
54
+ | gender | string | Male or female |
55
+ | age | int | Age in years (18-70) |
56
+ | age_group | string | Age bracket |
57
+ | income_quintile | string | Income group (lowest to highest) |
58
+ | education | string | Education level |
59
+ | employment_status | string | Employment category |
60
+ | monthly_income_usd | float | Monthly income in USD |
61
+ | income_stability | int | Income stability score (1-10) |
62
+ | credit_history | string | Credit history quality |
63
+ | has_bank_account | int | Has bank account (0/1) |
64
+ | credit_score | int | Credit score (0-850) |
65
+ | credit_need | int | Needs credit (0/1) |
66
+ | preferred_credit_source | string | Preferred lender type |
67
+ | loan_amount_requested_usd | float | Requested loan amount |
68
+ | collateral_available | string | Collateral type |
69
+ | loan_purpose | string | Purpose of loan |
70
+ | approved | int | Loan approved (0/1) |
71
+ | loan_disbursed_usd | float | Disbursed loan amount |
72
+ | interest_rate | float | Annual interest rate |
73
+ | loan_term_months | int | Loan term in months |
74
+ | monthly_payment_usd | float | Monthly payment |
75
+ | repayment_status | string | Current repayment status |
76
+ | rejection_reason | string | Reason for rejection |
77
+ | scenario | string | Burden scenario label |
78
+
79
+ ## Usage Example
80
+
81
+ ```python
82
+ import pandas as pd
83
+
84
+ # Load the combined dataset
85
+ df = pd.read_csv("credit_access_combined.csv")
86
+
87
+ # Analyze credit sources
88
+ sources = df[df['credit_need'] == 1]['preferred_credit_source'].value_counts()
89
+
90
+ # Predict loan approval
91
+ from sklearn.ensemble import RandomForestClassifier
92
+ from sklearn.model_selection import train_test_split
93
+
94
+ seekers = df[df['credit_need'] == 1].copy()
95
+ features = ['age', 'credit_score', 'income_stability', 'has_bank_account', 'collateral_available']
96
+ X = pd.get_dummies(seekers[features], drop_first=True)
97
+ y = seekers['approved']
98
+
99
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
100
+ model = RandomForestClassifier().fit(X_train, y_train)
101
+ print(f"Accuracy: {model.score(X_test, y_test):.2f}")
102
+ ```
103
+
104
+ ## Research Sources
105
+
106
+ - World Bank Global Findex Database 2025
107
+ - IMF Financial Access Survey 2024
108
+ - FSD Kenya credit market research 2024
109
+ - CGAP credit reporting research
110
+
111
+ ## Citation
112
+
113
+ ```bibtex
114
+ @dataset{credit_access_africa_2025,
115
+ title={Credit Access Patterns in Africa},
116
+ year={2025},
117
+ note={Synthetic dataset based on World Bank Findex and IMF data}
118
+ }
119
+ ```
credit_access_combined.csv ADDED
The diff for this file is too large to render. See raw diff
 
credit_access_high_burden.csv ADDED
The diff for this file is too large to render. See raw diff
 
credit_access_low_burden.csv ADDED
The diff for this file is too large to render. See raw diff
 
credit_access_moderate_burden.csv ADDED
The diff for this file is too large to render. See raw diff
 
generate_dataset.py ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Credit Access Patterns in Africa - Dataset Generator
3
+
4
+ DAG Structure:
5
+ country → formal_credit_availability, interest_rates
6
+ urban_rural → credit_institution_access
7
+ income_quintile → credit_score, loan_eligibility
8
+ employment_status → income_stability, loan_amount
9
+ credit_history → approval_probability
10
+ collateral → loan_amount, approval
11
+ loan_purpose → interest_rate, approval
12
+ approval → loan_disbursed, loan_amount_final
13
+
14
+ Parameter Evidence Table:
15
+ | Parameter | Value | Source |
16
+ |-----------|-------|--------|
17
+ | Formal credit access SSA | 15% | World Bank Findex 2025 |
18
+ | Informal credit access | 35% | World Bank Findex 2025 |
19
+ | Bank loan interest rates | 15-25% | World Bank 2024 |
20
+ | Microfinance rates | 25-45% | CGAP 2024 |
21
+ | Informal lender rates | 50-120% | FSD Kenya 2024 |
22
+ | Collateral requirement | 65% of formal loans | World Bank 2024 |
23
+ | Approval rate formal | 45% | World Bank 2024 |
24
+ | Approval rate informal | 75% | FSD Kenya 2024 |
25
+ | Credit bureau coverage | 12% SSA | World Bank 2024 |
26
+ | Default rate | 8-15% | IMF 2024 |
27
+ """
28
+
29
+ import numpy as np
30
+ import pandas as pd
31
+ from pathlib import Path
32
+
33
+ COUNTRIES = [
34
+ "Kenya", "Uganda", "Nigeria", "Ghana", "Tanzania", "Ethiopia",
35
+ "Malawi", "Zambia", "Senegal", "Rwanda", "Niger", "Mali",
36
+ "DRC", "Mozambique", "South Africa"
37
+ ]
38
+
39
+ YEARS = list(range(2018, 2026))
40
+
41
+ COUNTRY_CREDIT_ACCESS = {
42
+ "Kenya": 0.22, "Uganda": 0.15, "Tanzania": 0.14, "Ghana": 0.18,
43
+ "Nigeria": 0.16, "Ethiopia": 0.08, "Malawi": 0.12, "Zambia": 0.15,
44
+ "Senegal": 0.14, "Rwanda": 0.18, "Niger": 0.06, "Mali": 0.10,
45
+ "DRC": 0.05, "Mozambique": 0.08, "South Africa": 0.35
46
+ }
47
+
48
+ CREDIT_SOURCES = ["commercial_bank", "microfinance", "sacco", "digital_lender",
49
+ "informal_lender", "family_friends", "employer"]
50
+ LOAN_PURPOSES = ["business", "agriculture", "education", "housing",
51
+ "consumption", "emergency", "asset_purchase", "debt_consolidation"]
52
+ COLLATERAL_TYPES = ["property", "vehicle", "equipment", "savings", "guarantor", "none"]
53
+
54
+
55
+ def generate_scenario(n_samples: int, seed: int, scenario: str) -> pd.DataFrame:
56
+ rng = np.random.default_rng(seed)
57
+
58
+ country = rng.choice(COUNTRIES, n_samples)
59
+ year = rng.choice(YEARS, n_samples)
60
+
61
+ urban_rural = np.where(rng.random(n_samples) < 0.42, "urban", "rural")
62
+
63
+ gender = rng.choice(["male", "female"], n_samples, p=[0.48, 0.52])
64
+
65
+ age = rng.integers(18, 70, n_samples)
66
+ age_group = pd.cut(age, bins=[17, 25, 35, 45, 55, 70],
67
+ labels=["18-24", "25-34", "35-44", "45-54", "55+"])
68
+
69
+ income_quintile = rng.choice(["lowest", "second", "middle", "fourth", "highest"],
70
+ n_samples, p=[0.25, 0.22, 0.20, 0.18, 0.15])
71
+
72
+ education = rng.choice(
73
+ ["none", "primary", "secondary", "tertiary"],
74
+ n_samples, p=[0.18, 0.32, 0.35, 0.15]
75
+ )
76
+
77
+ employment_status = rng.choice(
78
+ ["employed_formal", "employed_informal", "self_employed", "farmer", "unemployed"],
79
+ n_samples, p=[0.12, 0.23, 0.30, 0.22, 0.13]
80
+ )
81
+
82
+ monthly_income = rng.lognormal(
83
+ mean=np.log(200) + np.select(
84
+ [income_quintile == "lowest", income_quintile == "second",
85
+ income_quintile == "middle", income_quintile == "fourth",
86
+ income_quintile == "highest"],
87
+ [-1.2, -0.5, 0.0, 0.5, 1.2]
88
+ ) + np.where(urban_rural == "urban", 0.4, 0.0),
89
+ sigma=0.7,
90
+ size=n_samples
91
+ )
92
+
93
+ income_stability = rng.integers(1, 11, n_samples)
94
+ income_stability = np.clip(
95
+ income_stability +
96
+ np.where(employment_status == "employed_formal", 3, 0) +
97
+ np.where(employment_status == "unemployed", -4, 0),
98
+ 1, 10
99
+ )
100
+
101
+ credit_history = rng.choice(
102
+ ["none", "limited", "good", "excellent"],
103
+ n_samples, p=[0.45, 0.30, 0.18, 0.07]
104
+ )
105
+
106
+ has_bank_account = (rng.random(n_samples) < 0.45).astype(int)
107
+
108
+ credit_score = rng.integers(0, 851, n_samples)
109
+ credit_score = np.clip(
110
+ credit_score +
111
+ np.where(income_quintile == "highest", 100, 0) +
112
+ np.where(credit_history == "good", 80, 0) +
113
+ np.where(credit_history == "excellent", 150, 0) +
114
+ np.where(credit_history == "none", -100, 0),
115
+ 0, 850
116
+ )
117
+
118
+ credit_need = (rng.random(n_samples) <
119
+ 0.40 +
120
+ np.where(employment_status == "self_employed", 0.15, 0.0) +
121
+ np.where(employment_status == "farmer", 0.10, 0.0) -
122
+ np.where(income_quintile == "highest", 0.10, 0.0)
123
+ ).astype(int)
124
+
125
+ preferred_source = np.empty(n_samples, dtype=object)
126
+ preferred_source[credit_need == 0] = "none"
127
+ need_mask = credit_need == 1
128
+
129
+ for i in range(n_samples):
130
+ if credit_need[i] == 1:
131
+ if has_bank_account[i]:
132
+ preferred_source[i] = rng.choice(CREDIT_SOURCES, p=[0.35, 0.18, 0.12, 0.15, 0.08, 0.10, 0.02])
133
+ else:
134
+ preferred_source[i] = rng.choice(CREDIT_SOURCES, p=[0.05, 0.15, 0.10, 0.10, 0.25, 0.30, 0.05])
135
+
136
+ loan_amount_requested = np.zeros(n_samples)
137
+ req_mask = credit_need == 1
138
+ loan_amount_requested[req_mask] = rng.lognormal(
139
+ mean=np.log(500) + np.log(monthly_income[req_mask] + 1) * 0.4,
140
+ sigma=0.6,
141
+ size=req_mask.sum()
142
+ )
143
+
144
+ collateral_available = np.empty(n_samples, dtype=object)
145
+ collateral_available[credit_need == 0] = "none"
146
+ collateral_available[req_mask] = rng.choice(
147
+ COLLATERAL_TYPES, req_mask.sum(),
148
+ p=[0.10, 0.05, 0.08, 0.15, 0.20, 0.42]
149
+ )
150
+
151
+ loan_purpose = np.empty(n_samples, dtype=object)
152
+ loan_purpose[credit_need == 0] = "none"
153
+ loan_purpose[req_mask] = rng.choice(
154
+ LOAN_PURPOSES, req_mask.sum(),
155
+ p=[0.30, 0.18, 0.12, 0.10, 0.12, 0.08, 0.07, 0.03]
156
+ )
157
+
158
+ approval_prob = np.zeros(n_samples)
159
+ approval_prob[req_mask] = np.clip(
160
+ 0.30 +
161
+ np.where(credit_score[req_mask] > 650, 0.25, 0.0) +
162
+ np.where(credit_score[req_mask] > 750, 0.15, 0.0) +
163
+ np.where(income_stability[req_mask] > 6, 0.10, 0.0) +
164
+ np.where(has_bank_account[req_mask] == 1, 0.10, 0.0) +
165
+ np.where(collateral_available[req_mask] != "none", 0.15, 0.0) -
166
+ np.where(credit_score[req_mask] < 450, 0.20, 0.0),
167
+ 0.05, 0.95
168
+ )
169
+
170
+ approved = np.zeros(n_samples, dtype=int)
171
+ approved[req_mask] = (rng.random(req_mask.sum()) < approval_prob[req_mask]).astype(int)
172
+
173
+ loan_disbursed = np.zeros(n_samples)
174
+ loan_disbursed[approved == 1] = loan_amount_requested[approved == 1] * rng.uniform(0.8, 1.0, approved.sum())
175
+
176
+ interest_rate = np.zeros(n_samples)
177
+ int_mask = approved == 1
178
+ base_rates = np.select(
179
+ [np.isin(preferred_source[int_mask], ["commercial_bank"]),
180
+ np.isin(preferred_source[int_mask], ["microfinance", "sacco"]),
181
+ np.isin(preferred_source[int_mask], ["digital_lender"]),
182
+ np.isin(preferred_source[int_mask], ["informal_lender"]),
183
+ np.isin(preferred_source[int_mask], ["family_friends", "employer"])],
184
+ [0.18, 0.32, 0.45, 0.80, 0.05],
185
+ default=0.25
186
+ )
187
+ interest_rate[int_mask] = base_rates + rng.uniform(-0.05, 0.05, int_mask.sum())
188
+
189
+ loan_term_months = np.zeros(n_samples, dtype=int)
190
+ loan_term_months[int_mask] = rng.choice([6, 12, 18, 24, 36, 48], int_mask.sum(),
191
+ p=[0.15, 0.35, 0.20, 0.18, 0.08, 0.04])
192
+
193
+ monthly_payment = np.zeros(n_samples)
194
+ monthly_payment[int_mask] = (
195
+ loan_disbursed[int_mask] * (1 + interest_rate[int_mask]) / loan_term_months[int_mask]
196
+ )
197
+
198
+ repayment_status = np.empty(n_samples, dtype=object)
199
+ repayment_status[approved == 0] = "not_applicable"
200
+ repay_mask = approved == 1
201
+ repayment_status[repay_mask] = rng.choice(
202
+ ["current", "late_30_days", "late_60_days", "defaulted", "paid_off"],
203
+ repay_mask.sum(),
204
+ p=[0.55, 0.15, 0.08, 0.07, 0.15]
205
+ )
206
+
207
+ application_rejection_reason = np.empty(n_samples, dtype=object)
208
+ application_rejection_reason[approved == 1] = "not_applicable"
209
+ reject_mask = (credit_need == 1) & (approved == 0)
210
+ application_rejection_reason[reject_mask] = rng.choice(
211
+ ["insufficient_income", "no_credit_history", "no_collateral",
212
+ "employment_status", "existing_debt", "documentation_issues"],
213
+ reject_mask.sum(),
214
+ p=[0.25, 0.22, 0.20, 0.15, 0.10, 0.08]
215
+ )
216
+
217
+ df = pd.DataFrame({
218
+ "country": country,
219
+ "year": year,
220
+ "urban_rural": urban_rural,
221
+ "gender": gender,
222
+ "age": age,
223
+ "age_group": age_group,
224
+ "income_quintile": income_quintile,
225
+ "education": education,
226
+ "employment_status": employment_status,
227
+ "monthly_income_usd": np.round(monthly_income, 2),
228
+ "income_stability": income_stability,
229
+ "credit_history": credit_history,
230
+ "has_bank_account": has_bank_account,
231
+ "credit_score": credit_score,
232
+ "credit_need": credit_need,
233
+ "preferred_credit_source": preferred_source,
234
+ "loan_amount_requested_usd": np.round(loan_amount_requested, 2),
235
+ "collateral_available": collateral_available,
236
+ "loan_purpose": loan_purpose,
237
+ "approved": approved,
238
+ "loan_disbursed_usd": np.round(loan_disbursed, 2),
239
+ "interest_rate": np.round(interest_rate, 3),
240
+ "loan_term_months": loan_term_months,
241
+ "monthly_payment_usd": np.round(monthly_payment, 2),
242
+ "repayment_status": repayment_status,
243
+ "rejection_reason": application_rejection_reason,
244
+ "scenario": scenario
245
+ })
246
+
247
+ return df
248
+
249
+
250
+ def main():
251
+ output_dir = Path(__file__).parent
252
+
253
+ scenarios = [
254
+ ("low_burden", 4000, 42),
255
+ ("moderate_burden", 5000, 43),
256
+ ("high_burden", 6000, 44)
257
+ ]
258
+
259
+ all_dfs = []
260
+ for scenario_name, n, seed in scenarios:
261
+ df = generate_scenario(n, seed, scenario_name)
262
+ all_dfs.append(df)
263
+
264
+ output_path = output_dir / f"credit_access_{scenario_name}.csv"
265
+ df.to_csv(output_path, index=False)
266
+ print(f"Generated {output_path}: {len(df)} records")
267
+
268
+ combined = pd.concat(all_dfs, ignore_index=True)
269
+ combined_path = output_dir / "credit_access_combined.csv"
270
+ combined.to_csv(combined_path, index=False)
271
+ print(f"Generated {combined_path}: {len(combined)} records")
272
+
273
+
274
+ if __name__ == "__main__":
275
+ main()