Cross-entropy loss, or log loss, measures the performance of a classification model whose output is a probability value between 0 and 1. Cross-entropy loss increases as the predicted probability diverges from the actual label. So predicting a probability of .012 when the actual observation label is 1 would be bad and result in a high loss value. A perfect model would have a log loss of 0.
The graph above shows the range of possible loss values given a true observation (isDog = 1). As the predicted probability approaches 1, log loss slowly decreases. As the predicted probability decreases, however, the log loss increases rapidly. Log loss penalizes both types of errors, but especially those predications that are confident and wrong!
Cross-entropy and log loss are slightly different depending on context, but in machine learning when calculating error rates between 0 and 1 they resolve to the same thing.
def CrossEntropy(yHat, y): if yHat == 1: return -log(y) else: return -log(1 - y)
In binary classification, where the number of classes \(M\) equals 2, cross-entropy can be calculated as:
If \(M > 2\) (i.e. multiclass classification), we calculate a separate loss for each class label per observation and sum the result.
- M - number of classes (dog, cat, fish)
- log - the natural log
- y - binary indicator (0 or 1) if class label \(c\) is the correct classification for observation \(o\)
- p - predicted probability observation \(o\) is of class \(c\)
Typically used for regression. It’s less sensitive to outliers than the MSE.
def Huber(yHat, y): pass
Mean Absolute Error, or L1 loss. Excellent overview below  and .
def L1(yHat, y): return np.sum(np.absolute(yHat - y))
Mean Squared Error, or L2 loss. Excellent overview below  and .
def MSE(yHat, y): return np.sum((yHat - y)**2) / y.size
def MSE_prime(yHat, y): return yHat - y