Skip to content

Validation, Hyperparameter and Feature Set Studies for a Weekly Sales Forecast

Published:
•41 min read

These studies are part of a series of experiments aimed at improving the way we design our models, in particular by investigating the introduction of an evaluation set, the choice of optimal hyperparameters for the models, and the selection of a relevant and reasonable feature set. The model is a LightGBM model that forecasts weekly sales per item and store, with one model per product category x zone. The results are shown relative to a baseline model, as a difference in points (or, in one figure, an index where the baseline is 100), not as absolute values.

The bias seen in these studies, under-forecasting high sellers and over-forecasting low sellers, is the subject of the next post.

Validation Set Study

Summary of findings

This study aimed to determine the most effective validation set strategy for early-stopping in our forecasting models, while preparing the ground for upcoming hyperparameter optimization and feature selection experiments. Five methods were evaluated across various product categories, zones, and cutoffs, using a fixed set of hyperparameters and the current production feature set, supplemented with all newly added features (covering SKU, BU, holidays, and price characteristics).

Results show that all evaluation set methods deliver similar or slightly better forecasting performance (≈ 2% WAPE improvement at horizon 4) compared to the production baseline, with the gain being more pronounced for lower selling classes (0 and 1). The last_year_exclusive_True method stands out slightly, triggering early stopping more often than the other methods and reducing training rounds, and thus lowering computation time while maintaining decent accuracy. Bias differences were generally small, with no method clearly outperforming across all horizons and product categories.

Given the marginal but consistent advantages and potential time savings, last_year_exclusive_True is recommended as the default approach moving forward.

Intro

A first study has been led to find the best validation set for an early-stopping training strategy. It is illustrated in the diagram below:

The three studies in order, and the plan of the validation set study.

Figure 1. The series of studies, and the validation set study’s plan, redrawn from the study’s sketch.

Setup of the Experimentation

We would like to investigate 4 different strategies for evaluating the error during training. These are listed below:

Diagram of the five validation set methods.

Figure 2. Which weeks feed the validation set in each method. A diagram, not data.

We conducted this experiment on the following perimeter:

Fixed set of hyperparameters

We fixed a set of hyperparameters in the middle of what we want to experiment with as hyperparameters.

num_leaves was first fixed at 131072 as planned, however this resulted in very slow training of the model (3.5h for 100 training rounds). We therefore decided to revert back to 256 for the purposes of the validation set experimentation.

HyperparameterProductionFixed for this study
objectivetweedietweedie
tweedie_variance_power1.61.6
boostinggbdtgbdt
bagging_freq11
bagging_fraction10.9
feature_fraction0.80.8
learning_rate0.070.07
max_depth256-1
num_leaves1024256
min_data_in_leaf10050
num_iterations10001000

Features

The features used represent the production features plus the preselection of features we added. The number of features evolves from 17 to 44:

Detailed Results

Comparison of early stopping results

For each perimeter we run all 5 methods, here are the average times it took for a run on each perimeter.

PerimeterAverage duration (minutes)Training size (rows)
small8.6~ 900 K
medium35.4~ 20 M
large92.6~ 60 M

Number of models trained = number of perimeters x number of methods x number of horizons = 3 x 5 x 8 = 120.

Default training rounds: 1000.

We run each validation set method on 3 perimeters, below is the total and average number of training rounds of experiments for the total number of models.

Mean best iteration and early stopping triggers per validation method.

Figure 3. Mean best iteration and number of early stops, per method. The mean RMSE of each method is left out: each is calculated on a different validation set, so direct comparison isn’t viable.

Advantages of using a validation set:

In conclusion, last_year_exclusive_True is the method that triggers early stopping and reduces the number of training rounds the most. When exclusive is False, we tend to overfit more by reducing RMSE further, which can lead to better accuracy if the model naturally underfits but runs the risk of overfitting otherwise. However, exclusive = False never triggered early stopping.

Comparison in metrics by selling class

For the simplification, we focus on one country in the analysis of results for the large and medium perimeters. Forecasts are compared to raw sales data to compute metrics.

WAPE 4: in terms of WAPE at horizon 4, the different methods using the evaluation set deliver similar results and outperform the baseline (production). Overall, we observe a 2% WAPE improvement, which is even more pronounced for selling classes 0 and 1. The “last_year_exclusive_False” method appears to stand out, showing a slight advantage for selling class 0, but gives similar results to other new models for the remaining selling classes.

Bias 4: from a bias perspective at horizon 4, the results are also similar for both lower and higher selling classes. The production model’s performance is also lower than that of the new methods. However, it is worth noting that at horizon 8, the production model appeared to perform better overall, due to the compensation between over-forecasts in lower selling classes and under-forecasts in higher selling classes.

Change in WAPE and change in absolute bias by selling class for the five validation methods against production.

Figure 4. WAPE and bias at horizon 4 by selling class, relative to production.

Comparison in metrics by product category

WAPE 4: the WAPE at horizon 4 highlights the same previous observations: the “last_year_exclusive_False” method stands out with better performance, especially for the large product category (-2% WAPE compared to production) and the small product category (-5% WAPE compared to production). But we can notice that except for the small product category, the performances of all new models are similar.

Bias 4: on the other hand, in terms of bias at horizon 4, the “last_year_exclusive_True” method performs better on the small product category, while “last_year_exclusive_False” performs better on the large product category. Production still remains the best performer on the medium product category.

Change in WAPE and change in absolute bias by perimeter for the five validation methods against production.

Figure 5. WAPE and bias at horizon 4 by perimeter, relative to production.

Conclusion

The different methods do not seem to stand out clearly in terms of WAPE or Bias. We recommend using the “last_year_exclusive_True” method, which comes slightly ahead and triggers early stopping the most often.

Annex: forecasts comparison for examples of time series

We compared the forecasts of the different models on examples of (sku, bu), selected on the WAPE at horizon 8 of last_year_exclusive_False: examples from the lowest and the highest WAPE, mixing high sellers and low sellers. They show single products’ weekly sales, so they are not reproduced here.

Annex: pre-hyperparameter experimentation study

Hyperparameters analysis

We analysed the model and extracted the tree structure for each tree for 2 models; the results are identical.

num_leaves:

min_data_in_leaf: we fixed this parameter at min_data_in_leaf = 50. Across all 1000 trees of this model, we observe 372 leaves out of 256000 with fewer than 50 examples.

This is normal behaviour. LightGBM checks min_data_in_leaf against a row count that it estimates from the sum of the hessians in each histogram bin, not against the exact count (source), so with an objective such as Tweedie, whose hessians differ from row to row, a leaf can end up with fewer rows than the limit.

For example, on a given model with min_data_in_leaf = 50, we found the following distribution of leaf sizes:

Share of leaves under 200, 100 and 50 rows in one model.

Figure 6. Leaf sizes in one model with min_data_in_leaf = 50, out of 409,600 leaves.

We propose to test the following hyperparameters during the next phase:

HyperparameterProductionProposed for the next phase
objectivetweedietweedie, mse, mae
tweedie_variance_power1.61.4, 1.6, 1.8
boostinggbdtgbdt, dart
bagging_freq11
bagging_fraction10.9
feature_fraction0.80.8
learning_rate0.070.07
max_depth256-1
num_leaves10244096, 8192, …
min_data_in_leaf10010, 50, 100
num_iterations10005000
L1_regularization (optional)0.2, 0.5, 0.8
L2_regularization (optional)0.2, 0.5, 0.8

We’ll try to set num_leaves to the max that will not result in very long training time. Then we’ll vary the other parameters.

Annex: features analysis

Analysis on:

They show similar results; subset 2 is presented below unless otherwise specified. All analyses are subset bound: they apply to that specific subset and model used. Their generalization should be verified rather than assumed.

Beeswarm plot

The beeswarm plot provides a global overview of SHAP values for selected features, with rows representing each feature ranked by the mean absolute SHAP value. The individual dots in each row are the SHAP values for that particular feature in each sample of the dataset. For numerical features we can observe the following:

For categorical features, these features seem to matter the most from the beeswarm plot: price type, region, colour, product nature, next and previous holiday name, product technicity level.

Importance plots for different cohorts

Feature correlation

With a clustering cutoff of 0.7 (linking features that have a distance < 0.7) and of 0.3 (distance < 0.3):

Mean absolute SHAP per feature with correlation clusters.

Figure 7. Mean |SHAP| per feature on subset 2, with the clusters at a cutoff of 0.3. SHAP values are in the model’s output units, not an accuracy metric.

More SHAP analysis will be conducted after phase 2 (hyperparameters experimentation).

Hyperparameter Set Study

Summary of findings

This study aimed to determine the most effective hyperparameters to support the change to our product category x zone modeling approach.

Our experimentations were conducted in a structured way (objective function, then complexity of tree, then regularization). First we tested many variations for each hyperparameter on one small perimeter to derive broad trends. We then proceeded by testing smaller variations of the hyperparameters on 3 perimeters.

Our analysis focused on understanding the effect of hyperparameters on models. We conducted several studies regarding the objective function and the fallacy of our evaluation metric, the potential for optimization for high sellers and the distribution of several key hyperparameters in the trained models.

We concluded the study by specifying 3 hyperparameter sets depending on the size of the cluster. The chosen hyperparameters reflect our key conclusions:

We also uncovered many interesting facts about our models:

Intro

This study is part of a series of experiments aimed at improving the way we design our models, in particular by investigating the introduction of an evaluation set, the choice of optimal hyperparameters for the models, and the selection of a relevant and reasonable feature set.

In this document, the focus is on experiments conducted to determine the most suitable hyperparameters for the data: the objective function, tree complexity, and regularization parameters.

Experimentation

At the last technical review, we presented our approach regarding the experiments aimed at improving the modeling process. The first step of this approach was a study on the validation set to ensure that the model makes proper use of early stopping (the validation set study above). As a reminder, the conclusion was to use as the evaluation set a data sample from the same forecast period of the previous year, while removing this sample from the training set.

The experiments are continuing with a study on hyperparameters. In order to reduce time of experimentation, our strategy is to proceed in 2 iterations:

In each iteration, we perform 3 steps of tuning: for the objective function, for the trees complexity (number of leaves and data per leaf), and for the regularization parameters.

Iteration 1: extensive combinations for one perimeter

We chose to set the number of iterations maximum to a high value (5000), since it will be in reality controlled by early stopping: from a preliminary experiment, we saw that generally models run at most for 1k to 3k rounds.

Step 1: objective function

Bias by selling class for five objectives, scaled to the largest absolute bias.

Figure 8. Bias by selling class for five of the objectives, scaled so the largest absolute bias in the chart is 100.

Step 2: complexity of trees

To choose the best combinations, we proceeded as follows:

Step 3: regularization

Note: these two regularization terms have different effects on the weights; L2 regularization (controlled by the lambda term) encourages the weights to be small, whereas L1 regularization (controlled by the alpha term) encourages sparsity, so it encourages weights to go to 0. In LightGBM the weights are the leaf values:

L = sum_i loss(y_i, h(x_i)) + 1/2 * lambda * sum_j w_j^2 + alpha * sum_j |w_j|

The results of this first test will be used to derive general tendencies about which hyperparameters work best. We will test the ones that are most interesting on the full 3 perimeters scope. Results show that more regularization gives better results.

Summary of iteration 1, steps 2 and 3: of the 20 tree-complexity variations, min_data_in_leaf 50 and 300 were almost always the best, with two dominant pairs, 512 leaves with 300 and 2048 leaves with 50, the latter kept for the regularization step, where more regularization gave better results.

Figure 9. Iteration 1, steps 2 and 3: the grids and what the study kept from them.

Iteration 2: test on 3 perimeters

Step 1: objective function

Results displayed are for the medium and small perimeters. Best: variance 1.6.

Change in WAPE and change in absolute bias for Tweedie power 1.4, 1.5 and 1.6.

Figure 10. Iteration 2, step 1, relative to production.

Step 2: complexity of trees

Spread across the ten tree settings of iteration 2, step 2: WAPE differs by 5 points on selling class 0, 3 on class 1 and at most 1 on the higher classes; bias by 7 points on classes 0 and 1 and 1 or 2 on the others.

Figure 11. Iteration 2, step 2, from the study’s annex: how far apart the ten settings are, per selling class.

Step 3: regularization

Results displayed are for the medium and small perimeters. Best: L1 3 and L2 3.

Change in WAPE and change in absolute bias for three regularization settings.

Figure 12. Iteration 2, step 3, relative to production.

Analysis

Objective function

Tweedie distribution with different power variances. Increasing the power variance shifts mass away from zero towards the right. For a power between 1 and 2, the Tweedie distribution has a point mass at zero and a continuous, right-skewed density on positive values (a compound Poisson gamma distribution, see scikit-learn’s generalized linear models).

Computed Tweedie distributions for four variance powers.

Figure 13. Computed, not from our data: a Tweedie distribution with mean 1 and dispersion 1 for four powers.

Theoretical analysis on the Tweedie power variance: we used negative log likelihood to fit a Tweedie function to the distribution of sales for each country in one product category. We also ran experiments with Tweedie 1.4, 1.5 and 1.6 and determined the optimal power variance. Below is a comparison of the optimal values, theoretical and experimental (WAPE + |Bias| as the metric):

Theoretical and experimental optimal Tweedie power per country.

Figure 14. Optimal Tweedie variance power per country, from the fit and from the runs. Countries are numbered.

Log-likelihood profile over the power, and a histogram of power estimates.

Figure 15. The fit behind the theoretical optimum: log-likelihood against the power for a joint fit including zeros (best at 1.55) and a fixed-mean fit on positive values (best at 1.65), and the distribution of power estimates.

We conclude that there is a correlation between the theoretical and experimental optimal power variance; in the future we can use the theoretical method to further optimize our power variance choices.

Optimizing for high sellers

The loss induced by each objective function incurred by missing the target by 1 sale:

Loss for a one-unit miss against actual sales, for four losses.

Figure 16. Computed from the loss formulas (Tweedie deviance), not from our data.

Gain in leaves distribution. We fixed min_gain_to_split = 0 so that the model adds additional splits in the trees even if the gain from those splits is very minimal. The distribution of the gain resulting from each split for a model shows that most splits add a gain lower than 100, with a peak around 2. However:

In LightGBM, the gain of a split with L1 term alpha and L2 term lambda is:

split_gain = T(G_left)^2 / (H_left + lambda) + T(G_right)^2 / (H_right + lambda) - T(G_parent)^2 / (H_parent + lambda)
T(G) = sign(G) * max(0, |G| - alpha)

where G and H are the sums of the gradients and hessians of the rows in each node, and the parent term is thresholded by alpha too (source).

Sales distribution. The distribution of our training set is a determinant factor for the model: if it’s biased towards low sellers, the model will optimize more for low sellers. Our sales distribution is right skewed, but it’s moderately balanced due to the split groups calculation, when we filter most of the low sellers. Our training distribution is defined by items in:

We can optimize more by reducing further the volume of low sellers, but overall our current method results in a pretty balanced distribution.

Sample weighting. We’ve established that using Tweedie we actually have more loss for misses on low sellers. This behaviour isn’t ideal; we want equivalent or even higher losses for higher sellers. To communicate this different processing to the model, we introduced sample weights where we give higher importance to high sellers samples. As a first approach we used log(target + 1) to define the importance of a sample.

The sample weight log(1 + y) against sales.

Figure 17. The weighting function, computed.

We ran the experiment on the medium and small perimeters:

Change in WAPE and bias change for the sample weighting runs.

Figure 18. Sample weighting runs, relative to the unweighted Tweedie 1.6 reference.

The results show the following:

Challenges with the experiment

WAPE = sum_t |y_t - y_hat_t| / sum_t |y_t|
     = sum_t w_t * |y_t - y_hat_t| / |y_t|,   with w_t = |y_t| / sum_t |y_t|

Share of samples per selling class: 47.6% in class 0, 31.0% in class 1, 18.6% in class 2, 2.2% in class 3 and 0.6% in class 4.

Figure 19. Forecast samples per selling class on the small perimeter, as shares.

Hyperparameters specialization

One of the big differences between the previous country cluster based modeling and the current product category x zone based modeling is the difference in sizes. In the product category x zone modeling we have many product categories with small amounts of rows. This necessitates hyperparameters that are different from those tuned on the larger clusters. Our three perimeters have about 20M (medium), 60M (large) and 0.9M (small) training rows.

From our training we also observe that the small clusters converge very quickly. They also require less complex trees than those of big clusters.

Training with the same set of hyperparameters for 3 types of clusters results in degraded performance. We therefore recommend splitting the clusters into 3 categories: big (> 40M rows), medium (between 1M and 40M) and small (< 1M), and using the following hyperparameters for each:

HyperparameterBig clusterMedium clusterSmall cluster
objectivetweedietweedietweedie
metrictweedietweedietweedie
tweedie_variance_power1.61.61.6
boostinggbdtgbdtgbdt
bagging_freq111
bagging_fraction0.90.80.7
feature_fraction0.80.80.8
learning_rate0.070.050.03
max_depth-1-1-1
min_data_in_leaf300300300
num_iterations300030003000
num_leaves256256256
lambda_l1333
lambda_l2333
min_gain_to_split000

Conclusion

HyperparameterOldNew
objectivetweedietweedie
metricrmsetweedie
tweedie_variance_power1.61.6
boostinggbdtgbdt
bagging_freq11
bagging_fraction10.8
feature_fraction0.80.8
learning_rate0.070.05
max_depth256-1
min_data_in_leaf100300
num_iterations10003000
num_leaves1024256
lambda_l103
lambda_l203
min_gain_to_split00

References

Feature Set Study

Summary of findings

This study aimed to determine the most effective feature set to support the change to our product category x zone modeling approach.

Our experimentations were conducted in a structured way and based on the results of the following analysis:

In the two steps of the experiments, we tested various feature sets. The goal was to remove features that don’t have any impact on the model and features that are strongly correlated.

We concluded the study by specifying one set of features which we deem the optimal one. The chosen feature set reflects our key conclusions:

For high sellers, our main focus, the chosen feature set allowed up to 3 points of WAPE improvement over the product category x zone baseline and up to 6 points of bias improvement over the product category x zone baseline.

Intro

The goal of this study is to determine which combination of features provides the best forecast performance, using hyperparameters from the hyperparameter set study.

Perimeter: the medium, large and small perimeters, each with its cutoff.

Across all experiments, multiple sets of features have been tested. Forecasts have been compared to those in production and those referring to the “product category x zone” split (actual hyperparameters and features). To find the best combination of features, metrics and visualisations have been computed, along with additional feature importance plots to assess the relevance of using some features.

Setup of the Experimentation

Terminology:

We structured the tests in two stages:

The following table shows the list of feature sets and their composition.

Matrix of features against the ten feature sets.

Figure 20. Feature sets and their composition.

Each of the tested models uses the set of hyperparameters defined during the hyperparameter experiments.

Detailed Results

Step 1: metrics

Results here are presented for the medium and small perimeters.

Change in WAPE and change in absolute bias for the step 1 feature sets.

Figure 21. Step 1, relative to production.

We can observe that the “minimalist_base” model performs better in terms of bias while achieving a WAPE similar to the other models. Therefore, we selected it as the basis for further iterations and introduced some improvements in a second step.

Step 1: visualization

The examples were chosen to represent the best and worst results obtained by our current production model. They show single products’ weekly sales, so they are not reproduced here.

Step 1: explainability

The following represent the feature importance for the different sets of features on different perimeters. We can observe the following:

Regarding some of the base features: we noticed that the behaviour of last year’s 3-week centred mean at horizon 1 is counterintuitive: when this feature is high, the model decreases its prediction. When looking closely, we discovered that this is due mainly to price type: when the latter is equal to “end of line”, last year’s 3-week centred mean happens to be high. The distribution of price type is clearly different for these rows, and price type is actually the feature that influences the model to decrease predictions.

Regarding price features:

From a performance point of view, minimalist_base was the most consistent method.

To choose the feature set for the second set of experiments, we looked at the correlation between features (the features that have a similarity of more than 70%). We can observe the following similar sets of features:

Four pairs of similar features: store category and store above 80%, product nature and product family above 70%, average sales last month and lag 1 above 70%, price type and the period price coefficient above 60%.

Figure 22. Similar feature pairs in the correlation plot.

We therefore decided to remove each of the features for one of the sets we tested in step 2 (split1 and split2).

Step 2: metrics

Results here are presented for the medium and small perimeters, by cutoff and selling class.

Change in WAPE and change in absolute bias for the step 2 feature sets.

Figure 23. Step 2, relative to production.

With this second step, we observe that the “minimalist_base” model still stands out among the best. The variant without sales lags performs very poorly, most likely because the model is misled by the low-selling classes, which make up the majority of the data.

Step 2: visualization

The same comparison on single products, on the medium and small perimeters and then on the large one, is not reproduced here for the same reason.

Step 2: explainability

The following represent the feature importance for the different sets of features for different perimeters. We can observe that:

Step 3: feature fraction

To combine the importance of deriving new relationships from less correlated features with the powerful effect of the sales derived features, we can use feature fraction to reduce the fraction of features used in each tree.

Change in WAPE for feature fraction 0.8, 0.6 and 0.4.

Figure 24. Feature fraction, relative to production.

Feature fraction set to 0.4 seems to be too low, so that it drastically reduces the performance of the model. 0.6 is very close to 0.8, which remains the optimal value.

Conclusion

We conclude the study by keeping minimalist_base as our most optimal feature set. We base our decision on the following:

For high sellers, our main focus, the chosen feature set allowed up to 3 points of WAPE improvement over the product category x zone baseline and up to 6 points of bias improvement over the product category x zone baseline. This improvement will be validated by the backtesting, where we’ll test the feature set on a multitude of perimeters and cutoffs.

Compared to the production model, the switch to the product category x zone strategy suffered from a degradation of WAPE and bias for small perimeters, while improving performance on big perimeters (not shown here). With our chosen feature set, we’ve removed the negative effect on small perimeters while keeping the positive effect on big perimeters. We’ve even improved the bias over the production model in some cases.

Change in WAPE and in absolute bias of the chosen feature set against the product category x zone baseline.

Figure 25. The chosen feature set, relative to the product category x zone model before the studies.

Future improvements

Annex: metrics with variations of minimalist_base on all perimeters

Change in WAPE and bias for the step 2 feature sets on the three perimeters.

Figure 26. The step 2 sets on all three perimeters, including the large one, relative to production.

Newsletter subscriptions are not currently available.