log_likelihood#

causalbase.scores.log_likelihood(dag, train, test, *, ess=1.0)[source]#

Return the log likelihood of test’s rows under dag, its parameters learned from train.

Discrete data gets the Bayesian predictive likelihood under a BDeu prior of equivalent sample size ess: the marginal likelihood of train and test together divided by that of train, which is the same for every DAG of an equivalence class. Continuous data gets the likelihood of a linear Gaussian model fitted to train by maximum likelihood.

Parameters:
dagDAG

The structure.

train, testDiscreteDataset or ContinuousDataset

Over the same variables, both discrete with the same levels or both continuous.

essfloat, default=1.0

Equivalent sample size of the BDeu prior, for discrete data.

Returns:
float

The total over test’s rows; divide by test.n_rows for a mean.

Raises:
ValueError

If the datasets do not share their variables, or their levels.