Computes a score to measure how well the given `BayesianModel` fits to the data set.
        (This method relies on the `local_score`-method that is implemented in each subclass.)

        Parameters
        ----------
        model: `BayesianModel` instance
            The Bayesian network that is to be scored. Nodes of the BayesianModel need to coincide
            with column names of data set.

        Returns
        -------
        score: float
            A number indicating the degree of fit between data and model

        Examples
        -------
        >>> import pandas as pd
        >>> import numpy as np
        >>> from pgmpy.estimators import K2Score
        >>> # create random data sample with 3 variables, where B and C are identical:
        >>> data = pd.DataFrame(np.random.randint(0, 5, size=(5000, 2)), columns=list('AB'))
        >>> data['C'] = data['B']
        >>> K2Score(data).score(BayesianModel([['A','B'], ['A','C']]))
        -24242.367348745247
        >>> K2Score(data).score(BayesianModel([['A','B'], ['B','C']]))
        -16273.793897051042

def score(self, model):
        """
        Computes a score to measure how well the given `BayesianModel` fits to the data set.
        (This method relies on the `local_score`-method that is implemented in each subclass.)

        Parameters
        ----------
        model: `BayesianModel` instance
            The Bayesian network that is to be scored. Nodes of the BayesianModel need to coincide
            with column names of data set.

        Returns
        -------
        score: float
            A number indicating the degree of fit between data and model

        Examples
        -------
        >>> import pandas as pd
        >>> import numpy as np
        >>> from pgmpy.estimators import K2Score
        >>> # create random data sample with 3 variables, where B and C are identical:
        >>> data = pd.DataFrame(np.random.randint(0, 5, size=(5000, 2)), columns=list('AB'))
        >>> data['C'] = data['B']
        >>> K2Score(data).score(BayesianModel([['A','B'], ['A','C']]))
        -24242.367348745247
        >>> K2Score(data).score(BayesianModel([['A','B'], ['B','C']]))
        -16273.793897051042
        """

        score = 0
        for node in model.nodes():
            score += self.local_score(node, model.predecessors(node))
        score += self.structure_prior(model)
        return score