fetch_network#
- causalbase.datasets.fetch_network(name, sample=0, *, data_home=None)[source]#
Download one sample of a bnlearn or bnRep network, with the network itself.
The samples are 100 of 5000 rows for each of the 24 discrete networks of bnlearn’s Bayesian Network Repository (Zenodo, 10.5281/zenodo.14917795) and of the 202 of bnRep (10.5281/zenodo.23561524). The first call downloads the network’s file and checks it; every later call reads the cache in
get_data_home(). Zenodo serves whole files, so the first sample of a network brings all 100 (from a few hundred kB to 200 MB formunin), and bnRep groups its networks of up to 20 variables into four files by size.- Parameters:
- namestr
A key of
list_remote_networks(). bnRep’s names carry the prefixbnrep_("bnrep_earthquake"is bnRep’s network of 40 variables,"earthquake"bnlearn’s of 5).- sampleint, default=0
Which of the 100 samples, from 0 to 99.
- data_homestr or path-like, optional
Folder of the cache; see
get_data_home().
- Returns:
- NetworkBundle
The sample, the true structure indexed like its columns, and the network.
- Raises:
- ValueError
If name or sample is not one of those available.
- OSError
If a download fails or does not match its checksum; nothing is left in the cache then.
Examples
>>> from causalbase import GES >>> from causalbase.datasets import fetch_network >>> from causalbase.metrics import shd >>> bundle = fetch_network("hepar2", sample=7) >>> shd(bundle.truth, GES().fit(bundle.data).dag_)