Log-Likelihood Ratio Estimation


In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
n_positive = 200
n_negative = 600
positive = np.random.randn(n_positive)
negative = -1 - 0.5 * np.random.randn(n_negative)
X = np.hstack([positive, negative])
y = np.hstack([
    np.ones((n_positive,), dtype=int),
    np.zeros((n_negative,), dtype=int)
])

In [3]:
_, bins, _ = hist(X, bins=50, alpha=0.);
subplot(2,1,1);
hist(positive, bins=bins, alpha=0.5, color='g');
hist(negative, bins=bins, alpha=0.5, color='r');
xlim(-3, 3);
subplot(2,1,2);
hist(positive, bins=bins, normed=True, alpha=0.5, color='g');
hist(negative, bins=bins, normed=True, alpha=0.5, color='r');
xlim(-3, 3); ylim(0, 1);



In [4]:
from pyannote.algorithms.stats.llr import LLRNaiveBayes
llr_prior = LLRNaiveBayes(equal_priors=False).fit(X, y)
llr = LLRNaiveBayes(equal_priors=True).fit(X, y)

In [5]:
t = np.linspace(-3, 3, 50)
plot(t, llr_prior.transform(t), label='Naive Bayes');
plot(t, llr.transform(t), label='Naive Bayes (equal priors)');
plot([-3, 3], [0, 0], 'k--');
ylim(-11, 11);
legend(loc=2);



In [6]:
from pyannote.algorithms.stats.llr import LLRNaiveBayes, LLRIsotonicRegression
llr_prior = LLRIsotonicRegression(equal_priors=False).fit(X, y)
llr = LLRIsotonicRegression(equal_priors=True).fit(X, y)

In [7]:
t = np.linspace(-3, 3, 50);
plot(t, llr_prior.transform(t), label='Isotonic Regression');
plot(t, llr.transform(t), label='Isotonic Regression (equal priors)');
plot([-3, 3], [0, 0], 'k--');
ylim(-11, 11);
legend(loc=4);