Complete the code to define a generative model that learns the joint probability of data and labels.
model = GenerativeModel(p_x_y=[1])A generative model learns the joint probability P(x, y) of data and labels.
Complete the code to define a discriminative model that learns the conditional probability of labels given data.
model = DiscriminativeModel(p_y_given_x=[1])A discriminative model learns the conditional probability P(y|x) of labels given data.
Fix the error in the code to train a discriminative model using maximum likelihood estimation.
loss = -sum(log([1](y|x)) for x, y in dataset)
Training a discriminative model uses the likelihood of labels given data, P(y|x).
Fill both blanks to complete the code that generates new data samples from a generative model.
samples = model.sample([1]) print('Generated samples:', [2])
We specify how many samples to generate and then print the generated samples.
Fill all three blanks to complete the code that compares generative and discriminative models on accuracy.
gen_model = GenerativeModel() disc_model = DiscriminativeModel() accuracy_gen = gen_model.evaluate_accuracy([1]) accuracy_disc = disc_model.evaluate_accuracy([2]) print('Generative accuracy:', accuracy_gen) print('Discriminative accuracy:', accuracy_disc) better_model = [3] if accuracy_gen > accuracy_disc else disc_model
Both models are evaluated on the same test data. The better model is chosen by comparing accuracies.