La desviación es una transformación de un cociente de probabilidad. En particular, consideramos que el modelo basado en la probabilidad de que después de algún accesorio que se ha hecho y comparar esto con la probabilidad de lo que se llama el modelo saturado. Este último es un modelo que tiene tantos parámetros como puntos de datos y se logra un ajuste perfecto, así que mirando a la razón de verosimilitud estamos midiendo, en cierto sentido, lo mucho que nuestro modelo ajustado es de un "ideal" del modelo.
En la regresión multinomial caso tenemos datos de la forma (x1,y1),(x2,y2),…,(xn,yn) donde yi k- vector que indica que la clase de observación de la i pertenece (exactamente una entrada contiene un uno y el resto son cero). Ahora bien, si el ajuste de un modelo que estima un vector de probabilidades de ˆp(x)=(ˆp1(x),ˆp2(x),…,ˆpk(x)) a continuación, el modelo basado en la probabilidad puede ser escrito
n∏i=1k∏i=jˆpj(xi)yij.
The saturated model on the other hand assigns probability one to each event that occurred, which means the vector of probabilities ˆpi is just equal to yi for each i and we can write the ratio of these likelihoods as
n∏i=1k∏j=1(ˆpj(xi)yij)yij.
To find the deviance we take minus two times the log of this quantity (this transformation has importance in mathematical statistics because of a connection with the χ2 distribution) to get
−2n∑i=1k∑j=1yijlog(ˆpj(xi)yij).
(It's also worth pointing out that we treat zero times the log of anything as zero in this situation. The reason for this is that it's consistent with the idea that the saturated likelihood should equal one.)
The only part of this that's peculiar to glmnet
is the way in which the function ˆp(x) is estimated. It's doing a constrained maximization of the likelihood and computing the deviance as the upper bound on ‖ is varied, with the model that achieves the smallest deviance on test data being considered a "best" model.
Regarding the question about log loss, we can simplify the multinomial deviance above by keeping only the non-zero terms and write it as -2 \sum_{i=1}^{n} \log [\hat{p}_{j_i} (x_i)], where j_i is the index of the observed class for observation i, que es el empírica de registro de la pérdida multiplicada por una constante. Para minimizar la desviación es en realidad equivalente a minimizar el registro de la pérdida.