...
/Calculating the log‐likelihood when ignoring the missing data
Calculating the log‐likelihood when ignoring the missing data
Learn the concept of log‐likelihood and refine the model.
Calculate the log‐likelihood when ignoring the missing data
def eval_qbn(model, prepare_data, data):results = model(prepare_data(data), hist=False)return round(log_likelihood(data,results['11'], # prob_a_bresults['01'], # prob_a_nbresults['10'], # prob_na_bresults['00'] # prob_na_nb), 3)print(eval_qbn(qbn, lambda dataset: list(filter(lambda item: item[1] is not None ,dataset)), data))
The function eval_qbn
in line 1 takes the qbn
-function as the model, but we can plug in any other model, too, as long as it takes a dataset of the given format and returns the results we obtain from Qiskit. The second parameter, prepare_data
, is a function that takes care of the missing data point. We put in our data and expect the dataset we put into our model in line 2.
The function returns the log-likelihood score of the given model in line 3. Therefore, we provide the probability measures we get from the quantum circuit in lines 4 to 7. Note that the states we get from the quantum circuit read from the right (qubit at position 0 represents ) to the left (qubit at position 1 represents ).
In this example, we provide a function that filters out the missing item (filter(lambda item: item[1] is not None)
) in line 10.
The results show a log-likelihood score of . As mentioned, the overall value does not say much. We can check how good it is when we compare it with other models.
Next, let’s try to fill in a value for the missing data. In three of the five cases where is 0
, is 0
, too. is ...