Skip to content

Instantly share code, notes, and snippets.

@oddskool
oddskool / c2st.py
Created May 17, 2018 09:09
Classifier Two Sample Tests (C2ST)
import numpy as np
from sklearn.linear import LogisticRegression
from sklearn.metrics import hamming_loss
def c2st(X, y, clf=LogisticRegression(), loss=hamming_loss, bootstraps=300):
"""
Perform Classifier Two Sample Test (C2ST) [1].
This test estimates if a target is predictable from features by comparing the loss of a classifier learning
the true target with the distribution of losses of classifiers learning a random target with the same average.