#Visualize Log Loss when True value = 1
#y-axis is log loss, x-axis is probabilty that label = 1
#As you can see Log Loss increases rapidly as we approach 0
#But increases slowly as our predicted probability gets closer to 1
import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import log_loss
x = [i*.0001 for i in range(1,10000)] # 10000
y = [log_loss([0,1 if i > 0 else 0],[[0.0001, 0.9999],[1-(i*.0001), i*.0001]],eps=1e-15) for i in range(1,10000,1)]
plt.plot(x, y)
plt.axis([-.05, 1.1, -.8, 10])
plt.title("Log Loss when true label = 1")
plt.xlabel("predicted probability")
plt.ylabel("log loss")
plt.show()
x = [i*.0001 for i in range(1,10000)]
y = [log_loss([1],[[i*.0001,1-(i*.0001)]],eps=1e-15) for i in range(1,10000,1)]
plt.plot(x, y)
plt.axis([-.05, 1.1, -.8, 10])
plt.title("Log Loss when true label = 1")
plt.xlabel("predicted probability")
plt.ylabel("log loss")
plt.show()
------------------------------------------------------------------ ValueError Traceback (most recent call last) <ipython-input-2-4b3d43fb690a> in <module>() 1 x = [i*.0001 for i in range(1,10000)] ----> 2 y = [log_loss([1],[[i*.0001,1-(i*.0001)]],eps=1e-15) for i in range(1,10000,1)] 3 4 plt.plot(x, y) 5 plt.axis([-.05, 1.1, -.8, 10]) /Users/Natsume/miniconda2/envs/ml/lib/python2.7/site-packages/sklearn/metrics/classification.pyc in log_loss(y_true, y_pred, eps, normalize, sample_weight, labels) 1620 raise ValueError('y_true contains only one label ({0}). Please ' 1621 'provide the true labels explicitly through the ' -> 1622 'labels argument.'.format(lb.classes_[0])) 1623 else: 1624 raise ValueError('The labels array needs to contain at least two ' ValueError: y_true contains only one label (1). Please provide the true labels explicitly through the labels argument.