model_hc_bic = bn.structure_learning.fit(df, methodtype='hc', scoretype='bic') # %% Try all methods vs score types model_hc_bic = bn.structure_learning.fit(df, methodtype='hc', scoretype='bic') model_hc_k2 = bn.structure_learning.fit(df, methodtype='hc', scoretype='k2') model_hc_bdeu = bn.structure_learning.fit(df, methodtype='hc', scoretype='bdeu') model_ex_bic = bn.structure_learning.fit(df, methodtype='ex', scoretype='bic') model_ex_k2 = bn.structure_learning.fit(df, methodtype='ex', scoretype='k2') model_ex_bdeu = bn.structure_learning.fit(df, methodtype='ex', scoretype='bdeu') bn.compare_networks(model, model_hc_bic, pos=G['pos']) # %% Example with dataset import bnlearn as bn DAG = bn.import_DAG('sprinkler') # Print cpds bn.print_CPD(DAG) # plot ground truth G = bn.plot(DAG) df = bn.sampling(DAG, n=100) # %% Inference using custom DAG import bnlearn as bn # Load asia DAG df = bn.import_example('asia') # from tabulate import tabulate
def test_compare_networks(): DAG = bn.import_DAG('Sprinkler', verbose=0) G = bn.compare_networks(DAG, DAG, showfig=False) assert np.all(G[0] == [[12, 0], [0, 4]])
# Structure learning model = bn.structure_learning.fit(df, verbose=0) # Plot G = bn.plot(model, verbose=0) model_hc_bic = bn.structure_learning.fit(df, methodtype='hc', scoretype='bic', verbose=0) # %% Try all methods vs score types model_hc_bic = bn.structure_learning.fit(df, methodtype='hc', scoretype='bic') model_hc_k2 = bn.structure_learning.fit(df, methodtype='hc', scoretype='k2') model_hc_bdeu = bn.structure_learning.fit(df, methodtype='hc', scoretype='bdeu') model_ex_bic = bn.structure_learning.fit(df, methodtype='ex', scoretype='bic') model_ex_k2 = bn.structure_learning.fit(df, methodtype='ex', scoretype='k2') model_ex_bdeu = bn.structure_learning.fit(df, methodtype='ex', scoretype='bdeu') bn.compare_networks(model, model_hc_bic, pos=G['pos'], verbose=0) # %% Example with dataset import bnlearn as bn DAG = bn.import_DAG('sprinkler', verbose=3) # Print cpds bn.print_CPD(DAG) # plot ground truth G = bn.plot(DAG, verbose=0) df = bn.sampling(DAG, n=100, verbose=3) # %% Inference using custom DAG import bnlearn as bn # Load asia DAG df = bn.import_example('asia')