I have been reading about Quantile Regression and the Quantile Loss function, but I have to admit I am a bit lost as how to practically implement it. I would like to use it to calculate the prediction errors of a Machine Learning algorithm (in my case Random Forest). I would like to do it manually without relying on packages (I am using R) so that I am able to understand (hopefully) exactly what's going on.
I read that the Quantile Loss Function has this formulation (Meinshausen, 2006):
$$ \begin{equation} l_{\alpha}(y, q) = \begin{cases} \alpha\vert y - q\vert, & y \gt q \\ (1 - \alpha)\vert y - q\vert, & y \le q \end{cases} \end{equation} \tag{1}\label{1} $$
, where $y$ is a given observation, $q$ is a given prediction, and $\alpha$ is a quantile value.
This way I know how to calculate the loss values $l$ given a chosen $\alpha$.
Reading from this answer, I see one has then to
add up each individual $l$ to get a loss $L$ for the whole model
like so:
$$ L_{\alpha}(y, q) = \sum_{i=1}^n l_{\alpha}(y_i, q_i) \tag{2}\label{2} $$
I am pretty lost as to how to use this information for my implementation.
Should I run the ML algorithm to calculate the predictions first ($q$), inject them in \ref{1} and sum as in \ref{2} to obtain $L$ (I would do this twice with two $\alpha$ values, e.g. 0.2 and 0.8)? If so, what should I do with $L$ then?
Meinshausen, Nicolai, and Greg Ridgeway. "Quantile regression forests." Journal of machine learning research 7.6 (2006).
predict.all = TI am able to get the predictions of all individual trees. This way I would be able to calculate the quantiles myself. I don't know if this would give the same results as performing Quantile Regression, but if it works I might switch to this method, although I was looking for something I could use with other algorithms as well. – umbe1987 Sep 14 '23 at 14:39