Metadata-Version: 2.4
Name: pakdata
Version: 0.1.1
Summary: Real, open, Pakistan-specific datasets for machine learning, with a scikit-learn style API.
Author: Junaid Ahmad
License-Expression: MIT
Project-URL: Homepage, https://github.com/junaidaslam2006/pakData
Project-URL: Source, https://github.com/junaidaslam2006/pakData
Project-URL: Issues, https://github.com/junaidaslam2006/pakData/issues
Project-URL: Changelog, https://github.com/junaidaslam2006/pakData/blob/main/CHANGELOG.md
Project-URL: Hugging Face, https://huggingface.co/collections/junaid008/pakdata-pakistan-datasets-for-ml-6b0c7f85e1540271d1c0dfa6
Project-URL: Kaggle, https://www.kaggle.com/junaidaslam00/datasets
Keywords: datasets,pakistan,machine-learning,scikit-learn,open-data
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: DATA_LICENSES.md
Requires-Dist: numpy>=1.21
Requires-Dist: pandas>=1.3
Provides-Extra: sklearn
Requires-Dist: scikit-learn>=1.0; extra == "sklearn"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: scikit-learn>=1.0; extra == "dev"
Dynamic: license-file

# pakdata 🇵🇰

**Real, open, Pakistan-specific datasets for machine learning, loaded the same way as `sklearn.datasets`.**

Nearly every ML tutorial trains on Boston houses, California districts or Pima diabetes patients.
`pakdata` gives students and researchers in Pakistan (and anyone curious about Pakistan) real local
data with the same familiar API: Lahore smog, Peshawar summers, the 2023 digital census, wheat yields,
the 2005 Kashmir earthquake, the 2022 floods.

```python
from pakdata import load_pak_weather

X, y = load_pak_weather(return_X_y=True)   # exactly like sklearn.datasets.load_*
```

Every value comes from a named public source, nothing is synthetic or AI-generated, and every dataset
ships with a data card that gives its source, license, units, caveats and suggested tasks.

## Get the data anywhere

| Where | For | How |
|---|---|---|
| [PyPI](https://pypi.org/project/pakdata/) | Python | `pip install pakdata` |
| [Hugging Face](https://huggingface.co/collections/junaid008/pakdata-pakistan-datasets-for-ml-6b0c7f85e1540271d1c0dfa6) | PyTorch / TensorFlow / pandas / DuckDB, online data viewer | `load_dataset("junaid008/pak_weather")` |
| [Kaggle](https://www.kaggle.com/junaidaslam00/datasets) | Notebooks, competitions, CSV download | e.g. [Pakistan Census 2023](https://www.kaggle.com/datasets/junaidaslam00/pakistan-census-2023-districts) |
| [OpenML](https://www.openml.org/search?type=data&sort=runs&q=pak_) | scikit-learn (`fetch_openml`), R, Julia, Java/Weka | `fetch_openml("pak_census_districts", version=1)` (6 of 8, see below) |
| This repo | Any language | CSV.gz files in [`pakdata/data/`](pakdata/data/) |

### Straight from scikit-learn (no pakdata install)

```python
from sklearn.datasets import fetch_openml

census = fetch_openml(data_id=48264, as_frame=True)   # same as name="pak_census_districts", version=1
X, y = census.data, census.target
```

| Dataset | OpenML ID |
|---|---|
| pak_census_districts | [48264](https://www.openml.org/d/48264) |
| pak_economy | [48265](https://www.openml.org/d/48265) |
| pak_cities | [48266](https://www.openml.org/d/48266) |
| pak_crops | [48267](https://www.openml.org/d/48267) |
| pak_floods_2022 | [48268](https://www.openml.org/d/48268) |
| pak_earthquakes | [48270](https://www.openml.org/d/48270) (compact copy: no `event_id`/`time`/`place` text columns) |

`pak_weather` and `pak_air_quality` exceed OpenML's upload size limit, so use pakdata, Hugging Face or Kaggle for those.

### All links per dataset

| Dataset | Hugging Face | Kaggle | OpenML |
|---|---|---|---|
| pak_weather | [link](https://huggingface.co/datasets/junaid008/pak_weather) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-weather-daily) | too large |
| pak_air_quality | [link](https://huggingface.co/datasets/junaid008/pak_air_quality) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-air-quality-pm25) | too large |
| pak_census_districts | [link](https://huggingface.co/datasets/junaid008/pak_census_districts) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-census-2023-districts) | [48264](https://www.openml.org/d/48264) |
| pak_economy | [link](https://huggingface.co/datasets/junaid008/pak_economy) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-economy-1960-2025) | [48265](https://www.openml.org/d/48265) |
| pak_crops | [link](https://huggingface.co/datasets/junaid008/pak_crops) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-crop-production) | [48267](https://www.openml.org/d/48267) |
| pak_earthquakes | [link](https://huggingface.co/datasets/junaid008/pak_earthquakes) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-earthquakes-1973-2025) | [48270](https://www.openml.org/d/48270) |
| pak_floods_2022 | [link](https://huggingface.co/datasets/junaid008/pak_floods_2022) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-floods-2022-districts) | [48268](https://www.openml.org/d/48268) |
| pak_cities | [link](https://huggingface.co/datasets/junaid008/pak_cities) | [link](https://www.kaggle.com/datasets/junaidaslam00/pakistan-cities-towns) | [48266](https://www.openml.org/d/48266) |

## Install

```bash
pip install pakdata            # Python package
pip install pakdata[sklearn]   # also installs scikit-learn
```

The datasets are bundled inside the package (about 2.8 MB in total), so loading works offline.

## Datasets (v0.1.0, snapshot 2026.11)

| Loader | Rows | Features | What it is | Default target | Source | License |
|---|---:|---:|---|---|---|---|
| `load_pak_weather` | 58,448 | 19 | Daily weather, 16 cities across all provinces + GB + AJK, 2016–2025 | `temp_max_c` | Open-Meteo / ERA5 (Copernicus) | CC BY 4.0 |
| `load_pak_air_quality` | 12,450 | 21 | Daily PM2.5 and other pollutants + weather, 10 cities, 2022-08 to 2025-12 | `pm2_5_ugm3` | Open-Meteo / CAMS (Copernicus) | CC BY 4.0 |
| `load_pak_census_districts` | 136 | 29 | 2023 digital census: population, growth, literacy, housing per district | `literacy_rate_pct` | Pakistan Bureau of Statistics | PBS open licence (attribution) |
| `load_pak_economy` | 66 | 47 | Annual economy & society indicators, 1960–2025 | `gdp_growth_pct` | World Bank WDI | CC BY 4.0 |
| `load_pak_crops` | 4,202 | 5 | Area, production and yield of 79 crops, 1961–2024 | `yield_kg_per_ha` | FAO FAOSTAT | CC BY 4.0 |
| `load_pak_earthquakes` | 9,124 | 16 | Earthquakes M≥4 in and around Pakistan, 1973–2025 | `mag` | USGS ComCat | US Public Domain |
| `load_pak_floods_2022` | 160 | 21 | Satellite-detected flood extent & population exposed per district, Aug–Sep 2022 | `flood_extent_sep08_14_km2` | UNOSAT via HDX | **CC BY-SA 4.0** |
| `load_pak_cities` | 575 | 6 | Populated places: location, province, elevation, population | `log_population` | GeoNames | CC BY 4.0 |

```python
import pakdata
pakdata.list_datasets()          # this table as a DataFrame
print(pakdata.load_pak_census_districts().DESCR)   # full data card
```

## API

Every `load_pak_*` function takes the same arguments:

| Argument | Default | Meaning |
|---|---|---|
| `return_X_y` | `False` | Return `(X, y)` instead of a `Bunch` |
| `as_frame` | `"auto"` | `True` gives pandas, `False` gives numpy, `"auto"` gives pandas when a feature is text/categorical (same rule as `sklearn.datasets.fetch_openml`) |
| `target` | `None` | Predict a different column, e.g. `load_pak_cities(target="province")` for classification |

The returned `Bunch` has `data`, `target`, `frame` (all columns), `feature_names`, `target_names`, `DESCR`,
`source`, `license`, `version` and `citation`. ID columns, raw dates and columns that would leak the target
are kept in `frame` but left out of `data`.

```python
from sklearn.linear_model import LinearRegression
from pakdata import load_pak_census_districts

census = load_pak_census_districts(as_frame=True)
model = LinearRegression().fit(census.data.select_dtypes("number"), census.target)
```

See [examples/quickstart.py](examples/quickstart.py) for four complete beginner exercises.

## Honest caveats (read the data cards)

- **Weather and air quality are modelled data** (ERA5 reanalysis, CAMS), not ground-station measurements. The Gilgit and Skardu mountain grid cells are much wetter and colder than the valley towns.
- **Time series need time-ordered splits.** Use train-on-past, test-on-future for weather, air quality and economy; random splits overstate accuracy.
- **Census 2023** covers the four provinces and ICT. AJK and Gilgit-Baltistan were not in the published results.
- **GeoNames populations** have uneven vintages and are not census figures.
- **Floods 2022** contains satellite exposure estimates (UNOSAT), not NDMA damage counts, because no openly licensed district-level damage table exists.

## Licenses

The **code** is MIT. Each **data file keeps its source license**; see [DATA_LICENSES.md](DATA_LICENSES.md).
If you redistribute `pak_floods_2022` or something derived from it, CC BY-SA 4.0 requires you to share it under the same license.
When you publish work that uses a dataset, cite it with `bunch.citation`.

## Reproducibility

Each dataset has a build script at `scripts/build_<name>.py`. It re-downloads the data from the original
source, cleans it the same way and writes the snapshot, so anyone can audit or refresh it.
The scripts that call Open-Meteo use its free non-commercial tier. Run them one at a time.

## Roadmap

- Image datasets: number plates, rickshaws/vehicles, local foods, Urdu handwriting
- NLP datasets: Urdu, Pashto, Hindko and Roman-Urdu text; speech
- Mirrors on OpenML (so `sklearn.datasets.fetch_openml("pak-weather")` works), Hugging Face and Kaggle
- More tabular data: PSX stocks, SBP monthly economic data, rainfall and river flows

## Citing pakdata

Use GitHub's **"Cite this repository"** button (from [`CITATION.cff`](CITATION.cff)), and also cite the
original source of each dataset you use: `print(load_pak_weather().citation)`.

## Contributing

To add a dataset, follow [CONTRIBUTING_DATASET.md](CONTRIBUTING_DATASET.md). The one rule: **real data from a named, openly licensed source, documented honestly.**
