Example of contrastive pessimistic likelihood estimation

We are going to implement the CPLE algorithm in Python using a subset extracted from the MNIST dataset. For simplicity, we are going to use only the samples representing the digits 0 and 1:

from sklearn.datasets import load_digitsimport numpy as npX_a, Y_a = load_digits(return_X_y=True)X = np.vstack((X_a[Y_a == 0], X_a[Y_a == 1]))Y = np.vstack((np.expand_dims(Y_a, axis=1)[Y_a==0], np.expand_dims(Y_a, axis=1)[Y_a==1]))nb_samples = X.shape[0]nb_dimensions = X.shape[1]nb_unlabeled = 150Y_true = np.zeros((nb_unlabeled,))unlabeled_idx = np.random.choice(np.arange(0, nb_samples, 1), replace=False, size=nb_unlabeled)Y_true = Y[unlabeled_idx].copy()Y[unlabeled_idx] = -1

After creating the restricted ...

Get Python: Advanced Guide to Artificial Intelligence now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.