Structure Scores

Compute structure scores.

Each model can be scored based on its structure. However, the score doesn’t have very straight forward interpretebility but can be used to compare different models. A higher score represents a better fit. This method only needs the model structure to compute the score. The structure score functionality can be found here: bnlearn.bnlearn.structure_scores().

param model:

The model whose score needs to be computed.

type model:

The bnlearn instance such as pgmpy.base.DAG or pgmpy.models.BayesianNetwork

param df:

The dataset against which to score the model.

type df:

pd.DataFrame instance

param scoring_method:

The following four scoring methods are supported currently: 1) K2Score 2) BDeuScore 3) BDsScore 4) BicScore

type scoring_method:

str ( k2 | bdeu | bds | bic )

param kwargs:

Any additional parameters parameters that needs to be passed to the scoring method.

type kwargs:

kwargs

returns:

Model score – A score value for the model.

rtype:

float

Examples

>>> import bnlearn as bn
>>> # Load example dataset
>>>
>>> df = bn.import_example('sprinkler')
>>> edges = [('Cloudy', 'Sprinkler'), ('Cloudy', 'Rain'), ('Sprinkler', 'Wet_Grass'), ('Rain', 'Wet_Grass')]
>>>
>>> # Make the Bayesian DAG
>>> DAG = bn.make_DAG(edges)
>>> model = bn.parameter_learning.fit(DAG, df)
>>>
>>> # Structure scores are stored in the model dictionary.
>>> model['structure_scores']
>>>
>>> # Compute the structure score for as specific scoring-method.
>>> bn.structure_scores(model, df, scoring_method="bic")