<jupyter_start><jupyter_text>Create BBN with structure and dataIf you know the BBN structure and have data, you can create a BBN using the structure and learn the parameters from the data. For now, the parameters are simply the raw counts (not-Bayesian). The method to use is from ``Factory.from_data()``.<jupyter_code>import pandas as pd
from pybbn.graph.factory import Factory

df = pd.read_csv('./data/data-from-structure.csv')
structure = {
    'a': [],
    'b': ['a'],
    'c': ['b']
}

bbn = Factory.from_data(structure, df)<jupyter_output><empty_output><jupyter_text>As usual, after you acquire a BBN, you can performe inference using an `InferenceController`.<jupyter_code>from pybbn.pptc.inferencecontroller import InferenceController

join_tree = InferenceController.apply(bbn)

for node, posteriors in join_tree.get_posteriors().items():
    p = ', '.join([f'{val}={prob:.5f}' for val, prob in posteriors.items()])
    print(f'{node} : {p}')
import networkx as nx

n, d = bbn.to_nx_graph()
nx.draw(n, with_labels=True, labels=d, node_color='r', alpha=0.5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1322992700729927, 'fraction_numerical': 0.002737226277372263, 'mean_word_length': 5.415204678362573, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '613920', 'license': 'Apache-2.0', 'n_tokens_mistral': 378, 'n_tokens_neox': 370, 'n_words': 108, 'path': 'docs/source/structure-data.ipynb', 'repo_name': 'vishalbelsare/py-bbn', 'size': '1096'}