This was originally a post on the Kaggle Forums for the Rossman Competition. I thought I'd repost it here as well.

Like many, if not most of the people here, I've been using some variation of $\ln(sales)$ as the parameter I've been fitting. Yesterday, I was wondering if I could come up a transform that more closely matched the RMSPE evaluation. So, I did a little math. If $p$ is the predicted value, $t$ is the target value and our transform is $f(x)$, then: \begin{align} RMSPE(p,t) &= \sqrt{\frac{1}{n}\sum \left(\frac{p - t}{t}\right) ^2} \\ P &\equiv f(p) = f(t + \delta) \approx f(t) + f'(t)\delta + \ldots \\ T &\equiv f(t) \\ \text{where } \delta & \equiv p - t \\ \end{align} Here, $P$ and $T$ are the transformed $p$ and $t$. Our goal is to choose $f$ in order to make $RMS(P,T)$ approximately equal to $RMSPE(p,t)$: $$RMS(P,T) = \sqrt{\frac{1}{n}\sum (P - T)^2} \\$$ All we need to get these two metrics to agree is choose $f$ such that: $$P - T \approx \frac{p - t}{t} \\$$ If we assume that $\delta$ is small, and drop all the higher order terms of the Taylor series, then we can make $RMS(P,T)$ approximately equal to $RMSPE(p,t)$: \begin{align} \Rightarrow f(t) + f'(t)\delta - f(t) &\approx \frac{p - t}{t} \\ \Rightarrow f'(t)\delta &\approx \frac{\delta}{t} \\ \Rightarrow f'(t) &\approx \frac{1}{t} \\ \Rightarrow f(x) &\approx \ln(x) + C \end{align} Here $C$ is an arbitrary constant. Since it cancels in computation of $RMS$, we can choose it to be zero.

So the log transform was right all along! At least under the, possibly dubious, assumption that predicted values are close to the target values. I didn't learn anything new, but at least I can feel better about doing what I was already doing.

This may be a well known result, but I hadn't seen it mentioned anywhere so I figured I'd write it up.

In the comments to the Kaggle forum post, BogareTAU pointed out that there is an alternative approach using the mean value theorem. That's a nice approach, with essentially the same result. Check out the comments on the original post if you are interested.