Classical regression models are obtained by choosing a model that minimizes an empirical estimation of the Mean Square Error (MSE). Other quality measures are used, in general for robustness reasons. This is the case of the Huber loss
for instance. Another example of regression quality measure is given by the Mean Absolute Percentage Error (MAPE). If x denotes the vector of explanatory variables (the input to the regression model), y denotes the target variable and g is a regression model, the MAPE of g is obtained by averaging the ratio
The MAPE is often used in practice because of its very intuitive interpretation in terms of relative error. The use of the MAPE is relevant in finance, for instance, as gains and losses are often measured in relative values. It is also useful to calibrate prices of products, since customers are sometimes more sensitive to
In real world applications, the MAPE is frequently used when the quantity to predict is known to remain way above zero. It was used for instance as the quality measure in a electricity consumption forecasting contest organized by GdF ecometering on datascience.net. More generally, it has been argued that
where enough data are available, see e.g. [2].
We study in this paper the consequences of using the MAPE as the quality measure for regression models. Section 2 introduces our notations and the general context. It recalls the definition of the MAPE. Section 3 is dedicated to a first
optimal regression model with respect to the MSE is given by the regression function (i.e., the conditional expectation of the target variable knowing the explanatory variables). Section 3 shows that an optimal model can also be defined for the MAPE. Section 4 studies the consequences of replacing MSE/MAE by the
dimension. We show in particular that MAE based measures can be used to upper bound MAPE ones. Section 5 proves a universal consistency result for Empirical Risk Minimization applied to the MAPE, using results from Section 4. Finally, Section 6 shows how to perform MAPE regression in practice. It adapts
obtained model on simulated data.
We use in this paper a standard regression setting in which the data are fully described by a random pair Z = (X, Y ) with values in . We are interested in finding a good model for the pair, that is a (measurable) function g from
) is “close to” Y . In the classical regression setting, the closeness of g(X) to Y is measured via the
risk, also called the mean
squared error (MSE), defined by
In this definition, the expectation is computed by respect to the random pair (X, Y ) and might be denoted to make this point explicit.
settings.
Let m denote the regression function of the problem, that is the function
from
It is well known (see e.g. [3]) that the regression function is the best model in the case of the mean squared error in the sense that ) minimizes
the set of all measurable functions from
More generally, the quality of a model is measured via a loss function, l, from . The point-wise loss of the model g is l(g(X), Y ) and the risk of
the model is
leads to the risk defined above as
The optimal risk is the infimum of over measurable functions, that is
where ) denotes the set of measurable functions from
to R. As
recalled above we have
As explained in the introduction, there are practical situations in which the risk is not a good way of measuring the closeness of g(X) to Y . We focus in this paper on the case of the mean absolute percentage error (MAPE) as an alternative to the MSE. Let us recall that the loss function associated to the
MAPE is given by
with the conventions that for all and that
MAPE-risk of model g is
Notice that according to Fubini’s theorem, implies in particular that
and thus that interesting models belong to
is the probability measure on
We will also use in this paper the mean absolute error (MAE). It is based on the absolute error loss,
risks, the MAE-risk is given by
A natural theoretical question associated to the MAPE is whether an optimal model exists. More precisely, is there a function such that for all models
Obviously, we have
A natural strategy to study the existence of is therefore to consider a point-wise approximation, i.e. to minimize the conditional expectation introduced above for each value of x. In other words, we want to solve, if possible, the
optimization problem
for all values of x.
introduce necessary and sufficient conditions for the problem to involve finite values, then we show that under those conditions, it has at least one global solution for each x and finally we introduce a simple rule to select one of the solutions.
3.1. Finite values for the point-wise problem60
To simplify the analysis, let us introduce a real valued random variable T
and study the optimization problem
Depending on the distribution of T and of the value of not always a finite value, excepted for m = 0. In this latter case, for any random variable T, J(0) = 1 using the above convention.
Let us consider an example demonstrating problems that might arise for be distributed according to the uniform distribution on [
1].
Then
If 1], we have
This example shows that when T is likely to take values close to 0, then
when as a finite expectation, that is when the probability that |T| is smaller than
decreases sufficiently quickly when
goes to zero.
More formally, we have the following proposition.
if and only if
If any of those conditions is not fulfilled, then
Proof. We have
If P(T = 0) > 0 then for all . Let us therefore consider the case P(T = 0) = 0. We assume m > 0, the case m < 0 is completely identical.
We have
A simple upper bounding gives
and symmetrically
This shows that J(m) is the sum of finite terms and of Because of the symmetry of the problem, we can focus on
. It is also obvious that
is finite if and only if
more operational conditions in the rest of the proof.
Let us therefore introduce the following functions:
We have obviously for all ). In addition
According to the monotone convergence theorem,
)) are finite, or both are infinite. In addition, we have
therefore is finite if and only if
)) is finite. So a sufficient and necessary condition for
to be finite is
A symmetric derivation shows that is finite if and only if
The conditions of Proposition 1 can be used to characterize whether ]0
]) decreases sufficiently quickly to ensure that J is not (almost) identically
equal to +. For instance, if
and the sum diverges, leading to (for
and thus the sum converges, leading to for all m (provided similar
3.2. Existence of a solution for the point-wise problem
If the conditions of Proposition 1 are not fulfilled, J(m) is infinite excepted in show that J(m) has at least one global minimum. This is done in the following
Proposition 2. Under the conditions of Proposition 1, J is convex and has at least one global minimum.
Proof. We first note that J is convex. Indeed for all is obviously convex. Then the linearity of the expectation allows to conclude
As 0 with either a > 0 or b < 0. Let us assume a > 0, the other case being symmetric. Then for
Then
and therefore lim
Similarly, if
and then
and therefore lim
Therefore, J is a coercive function and has at least a local minimum, which is global by convexity.
3.3. Choosing the minimum95
However, the minimum is not necessary unique, as J is not strictly convex. In general, the set of global minima will be a bounded interval of R. In this case, and by convention, we consider the mean value of the interval as the optimal solution.
As an example of such behavior, we can consider the case where T is a random variable on {1, 2, 3}, such that P(T = 1) = 0.3, P(T = 2) = 0.4 and
P(T = 3) = 0.3. Then the expected loss is
and the figure 1 illustrates that there is an infinity of solutions. Indeed when
More generally, for any random variable T, we have defined a unique value m, which is a global minimum of . Moving back to our problem, it ensures that the MAPE-regression function
introduced in 8 is well defined and takes finite values on
. As
is point-wise optimal, it is
Figure 1: Counterexample with an infinite number of solutions.
One of the most standard learning strategy is the Empirical Risk Minimization (ERM) principle. We assume given a training set (
which consists in n i.i.d. copies of the random pair Z = (X, Y ).
from . Given a loss function l, we denote
The empirical estimate of ) (called the empirical risk) is given by
Then the ERM principle consists in choosing in the class G the model that
minimizes the empirical risk, that is
The main theoretical question associated to the ERM principle is how to control ) in such a way that it converges to
. An extension of this question
is whether can be reached if G is allowed to depend on n: the ERM is said to
for any distribution of (X, Y ) (see Section 5).
It is well known (see e.g. [3] chapter 9) that ERM consistency is related to uniform laws of large numbers (ULLN). In particular, we need to control
quantities of the following form
This can be done via covering numbers or via the Vapnik-Chervonenkis dimension (VC-dim) of certain classes of functions derived from G. One might think that general results about arbitrary loss functions can be used to handle the case
Lipschitz property of l (see Lemma 17.6 in [4], for instance) that is not fulfilled by the MAPE.
The objective of this section is to analyze the effects over covering numbers (Section 4.2) and VC-dimension (Section 4.3) of using the MAPE as the loss
those analyses (Section 4.4).
4.1. Classes of functions
Given a class of models, G, and a loss function l, we introduce derived classes,
H(G, l) given by
and
4.2. Covering numbers
4.2.1. Notations and definitions
Let F be a class of positive functions from an arbitrary set Z to . The
supremum norm on F is given by
We also define . We have obviously
only in ), hence the absolute value.
Let be a dissimilarity on F, that is a positive and symmetric function from
to
that measures how two functions from F are dissimilar (in particular
can be used to characterize the complexity of F
Definition 1. Let F be a class of positive functions from Z to and
a dissimilarity on
a positive integer, a size
respect to
is a finite collection
of elements of F such that for all
f
Then the -covering number of F is defined as follow.
Definition 2. Let F be a class of positive functions from Z to be a dissimilarity on F and
0. Then the
-covering number of
), is the size of the smallest
-cover of F. If such a cover does not exists, the
The behavior of ) with respect to
characterizes the complexity of F as seen through
. If the growth when
0 is slow enough (for an adapted choice of
), then some uniform law of large numbers applies (see Lemma 1).
4.2.2. Supremum covering numbers
Supremum covering numbers are based on the supremum norm, that is
For classical loss functions, the supremum norm is generally ill-defined on H(G, l). For instance let be two functions from
), generated by
and a value of ). Then sup
A similar situation arises for the MAPE. Indeed, let be two functions from
, generated by
Thus unless G is very restricted there is always and
has the general form
0 and thus lim
definition to a subset of Z. This corresponds in practice to support assumptions on the data (X, Y ). Hypotheses on G are also needed in general. In this latter case, one generally assumes . In the former case, assumptions depends on the nature of the loss function.
For instance in the case of the MSE, it is natural to assume that |Y | is upper
with probability one. If (
In the case of the MAPE, a natural hypothesis is that |Y | is lower bounded
by (almost surely). If (
and therefore the supremum norm is well defined.
The case of the MAE is slightly different. Indeed when x is fixed, then for sufficiently large positive values of Similarly, for sufficient large negative values of
. In addition, we have the following proposition.
Proposition 3. Let G be an arbitrary class of models with and let
denote the supremum norm on
Let
Proof. Let 0 and let
be a minimal
cover of
) (thus
)). Let
be the functions from G associated to
and let
be the corresponding functions in
Indeed let h be an arbitrary element of ) associated
the corresponding function in
). Then for a given
We have then
For all
Then
and thus
which allows to conclude.
This Proposition shows that the covering numbers associated to a class of functions G under the MAPE are related to the covering numbers of the same class under the MAE, as long as Y stays away from too small values.
4.2.3. Lp covering numbers170
covering numbers are based on a data dependent norm. Based on the training set
, we define for
We have a simple proposition:
Proposition 4. Let G be an arbitrary class of models and a data set such
that , then for all
Proof. The proof is similar to the one of Proposition 3.
This Proposition is the adaptation of Proposition 3 to covering numbers.
4.3. VC-dimension
dimension (VC dimension). We recall first the definition of the shattering coeffi-cients of a function class.
Definition 3. Let F be a class of functions from be a positive
integer. Let be a set of
that is the number of different binary vectors of size n that are generated by functions of F when they are applied to
Then the VC-dimension is defined as follows.
Definition 4. Let F be a class of functions from . The VC-dimension
of F is defined by
Interestingly, replacing the MAE by the MAPE does not increase the VC-dim of the relevant class of functions.
Proposition 5. Let G be an arbitrary class of models. We have
Proof. Let us consider a set of k points shattered by
function ) such that
. Each
corresponds to a
We define a new set of k points, () as follows. If
). For those points and for any
y|.
1 (or
will never be possible). In addition when
0 and when
). Notice that min
0 (as there is a finite number of binary vectors
and thus , that is
. For
such that
and thus
. Then
This shows that for each binary vector , there is a function
shattered by
Therefore we can take
)) to get the conclusion.
If then k can be chosen arbitrarily large and
Using theorem 9.4 from [3], we can bound the covering number with a VC-dim based value. If
2,
1, and 0
,
then
Therefore, in practice, both the covering numbers and the VC-dimension of MAPE based classes can be derived from the VC-dimension of MAE based classes.
4.4. Examples of Uniform Laws of Large Numbers
Rephrased with our notations, Lemme 9.1 from [3] is
Lemma 1 (Lemma 9.1 from [3])be a class of functions from
for all
A direct application of Lemma 1 to H(G, l) gives
provided the support of the supremum norm coincides with the support of (X, Y ) and functions in H(G, l) are bounded.
In order to fulfill this latter condition, we have to resort on the same strategy
As in Section 4.2.2 let and let
be such that
almost surely, then
and
Then if ), Lemma 1 applies to
(resp. to
Similar results can be obtained for the MAPE. Indeed let us assume that
0 almost surely. Then if
This discussion shows that , the lower bound on |Y |, plays a very similar
MAE and the MSE. A very similar analysis can be made when using the covering numbers, on the basis of Theorem 9.1 from [3]. It can also be combined with the results obtained on the VC-dimension. Rephrased with our notations,
Theorem 9.1 from [3] is
Theorem 1 (Theorem 9.1 from [3]). Let F be a class of functions from Z to
[0
As for Lemma 1, we bound via assumptions on G and on Y . For
instance for the MAE, we have
and for the MAPE
Equation (20) can be combined with results from Propositions 4 or 5 to allow a comparison between the MAE and the MAPE. For instance, using the VCdimension results, the right hand side of equation (19) is bounded above by
24
while the right hand side of equation (20) is bounded above by
In order to obtain almost sure uniform convergence of those right hand side quantities must be summable (this allows one to apply the Borel-Cantelli Lemma). For fixed values of the VC dimension, of
this is always the case. If those quantities are allowed to depend on n, then
play symmetric roles for the MAE and the MAPE. Indeed for the MAE, a fast growth of with n might prevent the bounds to be summable. For instance, if
grows faster than
, then
does not converges to zero and the series is not summable. Similarly, if
converges too quickly to zero, for
summable. The following Section goes into more details about those conditions in the case of the MAPE.
We show in this section that one can build on the ERM principle a strongly
almost universal).
Theorem 2. Let Z = (X, Y ) be a random pair taking values in such that
0 almost surely (
is a fixed real number). Let (
(
be a series of independent copies of Z.
such that:
1. G
2. is dense in the set of
) functions from
to R for any
If in addition
and there is
then converges almost surely to
Proof. We use the standard decomposition between estimation error and approx-
imation error. More precisely, for , a class of functions,
We handle first the approximation error. As pointed out in Section 2, implies that
). Therefore we can assume there is a series (
of functions from ) such that
by definition of as an infimum.
Let us consider two models . For arbitrary x and y, we have
and thus
and therefore
and thus
This shows that lim
The estimation error is handled via the complexity control techniques studied
in the previous Section. Indeed, according to Theorem 1, we have (for p = 1)
with
Using the fact that log(
and
As lim
As lim
Therefore, for n sufficiently large, ) is dominated by a term of the form
with 0 and
0 (both depending on
). This allows to conclude that
. Then the Borel-Cantelli theorem implies that
The final part of the estimation error is handled in a traditional way. Let
There is
Then . By definition
and thus for all g,
By taking the infimum on , we have therefore
Applying again the hypothesis,
and therefore
As a consequence
The combination of this result with the approximation result allows us to conclude.
Notice that several aspects of this proof are specific to the MAPE. This is the
This is also the case of the estimation part which uses results from Section 4 that are specific to the MAPE.
The previous Sections have been dedicated to the analysis of the theoretical
MAPE regression and we compare it to MSE/MAE regression.
On a practical point of view, building a MAPE regression model consists in minimizing the empirical estimate of the MAPE over a class of models
is to solve
where the (are the realizations of the random variables (
Optimization wise, this is simply a particular case of median regression (which is in turn a particular case of quantile regression). Indeed, the quotient
implementation that supports instance weights can be used to find the optimal model. This is for example the case of quantreg R package [5], among others. Notice that when corresponds to linear models, the optimization problem is a simple linear programming problem that can be solved by e.g. interior point
For some complex models, instance weighting is not immediate. As an example of MAPE-ing a classical model we show in this section how to turn kernel quantile regression into kernel MAPE regression. Notice that kernel regression introduces regularization and thus is not a direct form of ERM.
6.1. From quantile regression to MAPE regression
6.1.1. Quantile regression
Let us assume given a Reproducing Kernel Hilbert Space (RKHS), H, of functions from (notice that
could be replaced by an arbitrary space
and . As always, we have
The standard way of building regression models based on a RKHS consists in optimizing a regularized version of an empirical loss, i.e., in solving an
optimization problem of the form
Notice that the reproducing property of H implies that there is
f(x
In particular, quantile regression can be kernelized via an appropriate choice for l. Indeed, let [0; 1] and let
, introduced in [7]:
The check-function is also called the pinball loss. Then, the kernel quantile optimization problem, treated in [8, 9], is defined by:
where 0 handles the trade-off between the data fitting term and the regular-
6.2. MAPE primal problem
To consider the case of the MAPE, one can change the equation (24) to (25):
Notice that for the sake of generality, we do not specify the value of in this derivation: thus equation (25) can be seen as a form of “relative quantile”.
standard MAPE, that is to . The practical relevance of the “relative quantile” remains to be assessed.
Using the standard way of handling absolute values and using f(x) = , we can rewrite the regularization problem (25) as a (primal) op-
where
6.2.1. MAPE dual problem
Let us denote ) the vector regrouping all the variables of the primal problem. We denote in addition:
max
where the are the Lagrange multipliers. Some algebraic manipulations show that problem (27) is equivalent to problem (28):
We can simplify the problem by introducing a new parametrisation via the variables . Then the value of w is obtained from constraint (29) as
). Constraints (30) can be rewritten into 1
those equations into account, the objective function becomes
Using constraints (31) and (32), the last two terms simplify as follows:
and thus the objective function is given by
where ) is the kernel matrix. This shows that the objective function can be rewritten so as to depend only on the new variables
. The last step of
The cases of constraints (29) and (30) have already been handled.
Notice that given an arbitrary , there is always
that
. However, constraints (31) and (32) combined with
and
0 show that
and
(and thus
) cannot be arbitrary, as we
. Conversely, it is easy to see that if
satisfies the constraints
, then there is
for k = 1, . . . , 4 such that
and such that the constraints (31), (32) and (33) are satisfied (take
6.2.2. Comparaison to the quantile regression
In the case of quantile regression, [8] shows that the dual problem is equivalent
to
In comparison to problem (34), one can remark that the modification of the
primal optimization problem is equivalent to changing the set of optimization in the dual optimization problem. More precisely, it is equivalent to reducing (resp. increasing) the “size” of the optimization set of
Thus, the smaller is , the larger is the optimization set of
. This permits
error is potentially bigger). Moreover, by choosing a very large value of C (or ), one can ensure the same optimal value of each
in MAE and MAPE dual problems. This surprising fact can be explained by noticing that a very large value of C corresponds to a very small value of
potential overfitting. When this overfitting appears, regardless of the loss function and thus the different loss functions are equivalent.
6.3. A simulation study
6.3.1. Generation of observations
described in section 6.1 on simulated data, and we compare the results to the ones obtained by kernel median regression. Experiments have been realized using a Gaussian kernel.
As in [8], we have simulated data according to the sinus cardinal function,
defined by
However, to illustrate the variation of the prediction according the proximity to zero, we add a parameter a and we define the translated sinus cardinal function by:
For experiments, we have generated 1000 points to constitute a training set, and 1000 other points to constitute a test set. As in [8], the generation process is the following:
with
estimation, we have computed for several values of a. The value of the regularization parameter C is chosen via a 5-fold cross-validation.
6.3.2. Results
Table 1: Summary of the experimental results: for each value of the translation parameter a, the table gives the MAPE of estimated on the test set. The table also reports the value of the regularization parameter C for both loss function.
Results of experiments are described in the table 1. As expected, in most
especially the case when values of y are close to zero.
6.3.3. Graphical illustration
Some graphical representations of are given on Figure 2. This Figure illustrates several interesting points:
• Up to translation, looks roughly the same for each a, whereas
• Red curves are closer to 0 than blue curves. One can actually show that,
• The red curve seems to converge toward the blue one for high values of a.
We have shown that learning under the Mean Absolute Percentage Error
particularly, we have shown the existence of an optimal model regarding to the MAPE and the consistency of the Empirical Risk Minimization. Experimental results on simulated data illustrate the efficiency of our approach to minimize the MAPE through kernel regressions, what also ensures its efficiency in application
is positive by design and remains quite far away from zero, e.g. in price prediction for expensive goods). Two open theoretical questions can be formulated from this work. A first question is whether the lower bound hypothesis on |Y | can be lifted: in the case of MSE based regression, the upper bound hypothesis on
cannot be adapted immediately to the MAPE because of the importance of the lower bound on |Y | in the approximation part of Theorem 2. A second question is whether the case of empirical regularized risk minimization can be shown to be consistent in the case of the MAPE.
Figure 2: Representation of estimation: in blue and
The authors thank the anonymous reviewers for their valuable comments that helped improving this paper.
Mathematical Statistics 35 (1) (1964) 73–101.
[2] J. S. Armstrong, F. Collopy, Error measures for generalizing about forecasting
(1992) 69 – 80.
Nonparametric Regression, Springer, New York, 2002.
[4] M. Anthony, P. L. Bartlett, Neural Network Learning: Theoretical Founda-
tions, Cambridge University Press, 1999.
[5] R. Koenker, quantreg: Quantile regression. r package version 5.05 (2013).
2004.
[7] R. Koenker, G. Bassett Jr, Regression quantiles, Econometrica: journal of
the Econometric Society (1978) 33–50.
[8] I. Takeuchi, Q. V. Le, T. D. Sears, A. J. Smola, Nonparametric quantile
[9] Y. Li, Y. Liu, J. Zhu, Quantile regression in reproducing kernel hilbert spaces,
Journal of the American Statistical Association 102 (477) (2007) 255–268.