Kossisoroyce commited on
Commit
0cfebf1
·
verified ·
1 Parent(s): 1c95dfb

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. README.md +18 -0
  2. generate_dataset.py +143 -0
  3. high.csv +0 -0
  4. low_burden.csv +0 -0
  5. moderate.csv +0 -0
README.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ task_categories:
4
+ - tabular-classification
5
+ - tabular-regression
6
+ language:
7
+ - en
8
+ tags:
9
+ - housing
10
+ - urbanization
11
+ - africa
12
+ - synthetic-data
13
+ - sub-saharan-africa
14
+ - tenure-security
15
+ - property-rights
16
+ size_categories:
17
+ - 10K<n<100K
18
+ ---
generate_dataset.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Dataset Generator: Housing Tenure Security Africa
3
+
4
+ Parameter Evidence Table:
5
+ | Parameter | Value | Source |
6
+ |-----------|-------|--------|
7
+ | Informal tenure prevalence | 60-80% in slums | UN-Habitat 2023 |
8
+ | Rental housing share | 30-50% urban | OECD Africa Urbanization 2025 |
9
+ | Title deed availability | 10-30% informal | World Bank land data |
10
+ | Eviction risk in informal | 15-40% | UN-Habitat estimates |
11
+ | Year range | 2018-2025 | Project scope |
12
+ | Countries | 15 African nations | Regional coverage |
13
+
14
+ DAG Structure:
15
+ country -> tenure_type -> security_level -> documentation -> risk_factors
16
+ """
17
+
18
+ import numpy as np
19
+ import pandas as pd
20
+ from pathlib import Path
21
+
22
+ COUNTRIES = [
23
+ 'Nigeria', 'Kenya', 'Ethiopia', 'Egypt', 'South Africa',
24
+ 'Tanzania', 'Morocco', 'Algeria', 'Ghana', 'Uganda',
25
+ 'Mozambique', 'Zambia', 'Malawi', 'Rwanda', 'Senegal'
26
+ ]
27
+
28
+ SCENARIOS = {
29
+ 'low_burden': {'n': 4000, 'informal_pct': 0.45, 'seed': 42},
30
+ 'moderate': {'n': 5000, 'informal_pct': 0.60, 'seed': 43},
31
+ 'high': {'n': 6000, 'informal_pct': 0.75, 'seed': 44}
32
+ }
33
+
34
+ CITIES = {
35
+ 'Nigeria': ['Lagos', 'Kano', 'Ibadan'],
36
+ 'Kenya': ['Nairobi', 'Mombasa', 'Kisumu'],
37
+ 'Ethiopia': ['Addis Ababa', 'Dire Dawa'],
38
+ 'Egypt': ['Cairo', 'Alexandria'],
39
+ 'South Africa': ['Johannesburg', 'Cape Town'],
40
+ 'Tanzania': ['Dar es Salaam'],
41
+ 'Morocco': ['Casablanca', 'Rabat'],
42
+ 'Algeria': ['Algiers'],
43
+ 'Ghana': ['Accra', 'Kumasi'],
44
+ 'Uganda': ['Kampala'],
45
+ 'Mozambique': ['Maputo', 'Beira'],
46
+ 'Zambia': ['Lusaka'],
47
+ 'Malawi': ['Lilongwe', 'Blantyre'],
48
+ 'Rwanda': ['Kigali'],
49
+ 'Senegal': ['Dakar']
50
+ }
51
+
52
+ def dag_sample_tenure_type(informal_pct, rng):
53
+ weights = [informal_pct, 0.35, 0.15, 0.08]
54
+ weights = [w / sum(weights) for w in weights]
55
+ return rng.choice(['informal', 'rental', 'owner_occupied', 'customary'], p=weights)
56
+
57
+ def dag_sample_security_level(tenure_type, informal_pct, rng):
58
+ security_map = {
59
+ 'informal': rng.uniform(0.2, 0.5),
60
+ 'rental': rng.uniform(0.4, 0.7),
61
+ 'owner_occupied': rng.uniform(0.7, 0.95),
62
+ 'customary': rng.uniform(0.3, 0.6)
63
+ }
64
+ if tenure_type == 'informal':
65
+ security_map['informal'] *= (1 - informal_pct * 0.3)
66
+ return round(security_map[tenure_type], 3)
67
+
68
+ def dag_sample_documentation(tenure_type, security, rng):
69
+ doc_chances = {
70
+ 'informal': 0.15,
71
+ 'rental': 0.55,
72
+ 'owner_occupied': 0.75,
73
+ 'customary': 0.25
74
+ }
75
+ has_title = rng.random() < doc_chances.get(tenure_type, 0.3)
76
+
77
+ return {
78
+ 'has_title_deed': has_title,
79
+ 'has_formal_lease': rng.random() < doc_chances.get(tenure_type, 0.3) * 0.8,
80
+ 'proof_of_occupancy': rng.random() < 0.7,
81
+ 'registration_status': rng.choice(['registered', 'pending', 'none'])
82
+ }
83
+
84
+ def generate_dataset(scenario, output_dir):
85
+ config = SCENARIOS[scenario]
86
+ rng = np.random.default_rng(config['seed'])
87
+
88
+ data = {
89
+ 'country': [],
90
+ 'city': [],
91
+ 'year': [],
92
+ 'tenure_type': [],
93
+ 'security_score': [],
94
+ 'has_title_deed': [],
95
+ 'has_formal_lease': [],
96
+ 'proof_of_occupancy': [],
97
+ 'registration_status': [],
98
+ 'years_in_tenure': [],
99
+ 'eviction_risk_pct': [],
100
+ 'perceived_security': [],
101
+ 'willingness_to_invest': [],
102
+ 'tenure_type_detail': [],
103
+ 'landlord_relationship': [],
104
+ 'rent_control_applicable': []
105
+ }
106
+
107
+ for _ in range(config['n']):
108
+ country = rng.choice(COUNTRIES)
109
+ city = rng.choice(CITIES.get(country, ['Unknown']))
110
+ year = rng.integers(2018, 2026)
111
+
112
+ tenure_type = dag_sample_tenure_type(config['informal_pct'], rng)
113
+ security = dag_sample_security_level(tenure_type, config['informal_pct'], rng)
114
+ docs = dag_sample_documentation(tenure_type, security, rng)
115
+
116
+ eviction_risk = (1 - security) * 100
117
+
118
+ data['country'].append(country)
119
+ data['city'].append(city)
120
+ data['year'].append(year)
121
+ data['tenure_type'].append(tenure_type)
122
+ data['security_score'].append(security)
123
+ data['has_title_deed'].append(docs['has_title_deed'])
124
+ data['has_formal_lease'].append(docs['has_formal_lease'])
125
+ data['proof_of_occupancy'].append(docs['proof_of_occupancy'])
126
+ data['registration_status'].append(docs['registration_status'])
127
+ data['years_in_tenure'].append(int(rng.uniform(1, 25)))
128
+ data['eviction_risk_pct'].append(round(eviction_risk, 1))
129
+ data['perceived_security'].append(rng.choice(['very_secure', 'secure', 'insecure', 'very_insecure']))
130
+ data['willingness_to_invest'].append(round(rng.uniform(0.1, 0.9), 2))
131
+ data['tenure_type_detail'].append(rng.choice(['formal', 'informal', 'customary', 'communal']))
132
+ data['landlord_relationship'].append(rng.choice(['family', 'private', 'government', 'community']))
133
+ data['rent_control_applicable'].append(rng.choice([True, False], p=[0.2, 0.8]))
134
+
135
+ df = pd.DataFrame(data)
136
+ output_dir.mkdir(parents=True, exist_ok=True)
137
+ df.to_csv(output_dir / f'{scenario}.csv', index=False)
138
+ print(f"Generated {scenario}: {len(df)} rows")
139
+
140
+ if __name__ == '__main__':
141
+ base_dir = Path(__file__).parent
142
+ for scenario in SCENARIOS:
143
+ generate_dataset(scenario, base_dir)
high.csv ADDED
The diff for this file is too large to render. See raw diff
 
low_burden.csv ADDED
The diff for this file is too large to render. See raw diff
 
moderate.csv ADDED
The diff for this file is too large to render. See raw diff