erdogant / bnlearn

Python library for learning the graphical structure of Bayesian networks, parameter learning, inference and sampling methods.
https://erdogant.github.io/bnlearn
Other
463 stars 45 forks source link

Sampling from Bayesian network? #67

Open notna07 opened 1 year ago

notna07 commented 1 year ago

I'm interested in using Bayesian networks for synthetic data generation experiments. I can fit my data, and look at the structure, and even simulate new data. However, it seems with this package there is no way of simulating data conditioned on known variables? e.i. say I wanted to make more women for the Titanic dataset to have balanced classes, or something similar - is there a way of providing a dataframe and have the BN fill out the missing values and columns?

EDIT: To clarify, I was looking for something like samples = bn.sampling(model, n_samples, {Sex: 1, 'Pclass': 0}) or just adding in a dataframe instead of the n_samples,

condition_df = pd.DataFrame(np.ones(100), columns=['Sex'])

samples = bn.sampling(model, condition_df)

but did not find anything in the documentation