1
$\begingroup$

I'm trying to understand the multiclass log-loss as described in sk-learns documentation.

The wording ' Let the true labels (Y) for a set of samples be encoded as a 1-of-K binary indicator matrix...', implies to me that we have K different matrices, one for each class, the elements of which take values of 0 or 1 indicating the presence of that class (a kind of one-hot coding?).

Or is it that Y is a K by N matrix, N the number of samples? This makes far more sense to me, maybe I'm just misinterpreting the wording.

Can anyone point me to a more thorough explanation of the multi-class case? I can find plenty on the binary case, not so much multi-class.

$\endgroup$

1 Answer 1

1
$\begingroup$

Note what follows in the documentation after what you quote:

Let the true labels for a set of samples be encoded as a $1$-of-$K$ binary indicator matrix $Y$, i.e., $y_{i,k}=1$ if sample $i$ has label $k$ taken from a set of $K$ labels.

This is standard matrix nomenclature: $Y$ is a matrix with $N$ rows and $K$ columns (not $K$ by $N$ as you suspect), with the $i$-th row encoding the class membership of the $i$-th sample with a single $1$ at position $k$.

Incidentally, you could test your understanding by creating a small toy example, say with $N=2$ and $K=3$, and feeding it to the log_loss() function. It should quickly become apparent that $Y\in\mathbb{R}^{N\times K}$, not $Y\in\mathbb{R}^{K\times N}$ or something even stranger.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.