How should I formulate the loss function/objective for this predictive modeling problem? Let's say I have a big department store, selling all kinds of products, like clothing, shoes, cosmetics and electronics, etc. The data I have are daily sales by each item, like
Date            Product-Name        Price    Promotion    Category ...
2018-12-19      Bt-gloves           60       0.8          Clothing
2018-12-19      GY-short-sleeves    430      1            Clothing
2018-12-18      SN-Alpha-10         1290     1            Electronic
2018-11-20      LAM-Cream           780      0.95         Cosmetic
...

But, what I am trying to predict are daily sales per category. And the loss function I am going to use is root mean square.

My question is what should be the best approach? Should I aggregate the data by category and train my model, or should I train the model just by using the daily sales by item and then aggregate them by category. If I pick the first approach, I will lose a part of the data by aggregating. But, if I am going to pick the second one, how should I adjust the loss function?
 A: In theory it should not matter, assuming the errors of the products are uncorrelated:
$$
\begin{align*}
\text{RMSE}
&= \sqrt {\sum_i ( S_{cat_i} - \hat S_{cat_i})^2} & \text{over all categories}\\
&= \sqrt {\sum_i ( \sum_{j\ \in cat_i} y_j - \sum_{j\ \in cat_i} \hat y_j)^2}\\
&= \sqrt {\sum_i ( \sum_{j\ \in cat_i} y_j -\hat y_j)^2}\\
&= \sqrt {\sum_i ( \sum_{j\ \in cat_i} e_j)^2} & e_j \text{ as the error for product }j \\
&= \sqrt {\sum_i ( \sum_{j\ \in cat_i} e_j^2 + 2 \sum_{k\ \in cat_i} \sum_{l} e_l e_k )} & \text{but }e_l e_k = 0 \text{ if uncorrelated} \\
&= \sqrt {\sum_i ( \sum_{j\ \in cat_i} e_j^2)} \\
&= \sqrt {\sum_i ( \sum_{j\ \in cat_i} e_j^2)} = \sqrt {\sum_{all\ products} e_n^2} & \text{the same as over all products}
\end{align*}
$$
This is sloppy but you get the idea.
In practice I would suggest trying both approaches and determine which one fairs better by doing cross validation.
My guess would be that grouping first works better because of the interaction term in the above derivation which will lead to small errors in different products adding up, but now that's definitely just hearsay from my part. Would be interesting to get back the results from your experiments!
