(actual, predicted)
| 31 | # whose output is a probability value between 0 and 1. |
| 32 | # -> loss increases as the predicted probability diverges from the actual label |
| 33 | def cross_entropy(actual, predicted): |
| 34 | EPS = 1e-15 |
| 35 | predicted = np.clip(predicted, EPS, 1 - EPS) |
| 36 | loss = -np.sum(actual * np.log(predicted)) |
| 37 | return loss # / float(predicted.shape[0]) |
| 38 | |
| 39 | # y must be one hot encoded |
| 40 | # if class 0: [1 0 0] |
no outgoing calls
no test coverage detected