Alasan R2
Alasan R2
ABSTRACT
Regression analysis makes up a large part of supervised machine learning, and
consists of the prediction of a continuous independent target from a set of other
predictor variables. The difference between binary classification and regression is in
the target range: in binary classification, the target can have only two values (usually
encoded as 0 and 1), while in regression the target can have multiple values. Even if
regression analysis has been employed in a huge number of machine learning studies,
no consensus has been reached on a single, unified, standard metric to assess the
results of the regression itself. Many studies employ the mean square error (MSE)
and its rooted variant (RMSE), or the mean absolute error (MAE) and its percentage
variant (MAPE). Although useful, these rates share a common drawback: since their
values can range between zero and +infinity, a single value of them does not say
much about the performance of the regression with respect to the distribution of the
ground truth elements. In this study, we focus on two rates that actually generate a
high score only if the majority of the elements of a ground truth group has been
correctly predicted: the coefficient of determination (also known as R-squared or R2)
and the symmetric mean absolute percentage error (SMAPE). After showing their
mathematical properties, we report a comparison between R2 and SMAPE in several
use cases and in two real medical scenarios. Our results demonstrate that the
Submitted 26 March 2021
coefficient of determination (R-squared) is more informative and truthful than
Accepted 15 June 2021
Published 5 July 2021 SMAPE, and does not have the interpretability limitations of MSE, RMSE, MAE and
Corresponding author
MAPE. We therefore suggest the usage of R-squared as standard metric to evaluate
Davide Chicco, regression analyses in any scientific domain.
[Link]@[Link]
Academic editor
Subjects Data Mining and Machine Learning, Data Science, Artificial Intelligence
Yilun Shang
Keywords Regression, Regression evaluation, Regression evaluation rates, Coefficient of
Additional Information and determination, Mean square error, Mean absolute error, Regression analysis
Declarations can be found on
page 18
DOI 10.7717/peerj-cs.623 INTRODUCTION
Copyright The role played by regression analysis in data science cannot be overemphasised:
2021 Chicco et al. predicting a continuous target is a pervasive task not only in practical terms, but also at a
Distributed under conceptual level. Regression is deeply investigated even nowadays, to the point of still
Creative Commons CC-BY 4.0 being worth of considerations in top journals (Jaqaman & Danuser, 2006; Altman &
Krzywinski, 2015; Krzywinski & Altman, 2015), and widespread used also in the current
How to cite this article Chicco D, Warrens MJ, Jurman G. 2021. The coefficient of determination R-squared is more informative than
SMAPE, MAE, MAPE, MSE and RMSE in regression analysis evaluation. PeerJ Comput. Sci. 7:e623 DOI 10.7717/peerj-cs.623
scientific war against COVID-19 (Chan et al., 2021; Raji & Lakshmi, 2020; Senapati et al.,
2020; Gambhir et al., 2020). The theoretical basis of regression encompasses several
aspects revealing hidden connections in the data and alternative perspectives even up to
broadly speculative view: for instance, interpreting the whole statistical learning as a
particular kind of regression (Berk, 2020), or framing deep neural networks as recursive
generalised regressors (Wüthrich, 2020), or even provocatively pushing such
considerations to the limit of setting the whole of statistics under the regression framework
(Hannay, 2020). The relevancy of the topic is clearly reflected in the wide and
heterogeneous literature covering the different aspects and insights of the regression
analysis, from general overviews (Golberg & Cho, 2004; Freund, Wilson & Sa, 2006;
Montgomery, Peck & Vining, 2021), to more technical studies (Sykes, 1993; Lane, 2002) or
articles outlining practical applications (Draper & Smith, 1998; Rawlings, Pantula &
Dickey, 2001; Chatterjee & Hadi, 2015), including handbooks (Chatterjee & Simonoff,
2013) or works covering specific key subtopics (Seber & Lee, 2012). However, the reference
landscape is far wider: the aforementioned considerations stimulated a steady flow of
studies investigating more philosophically oriented arguments (Allen, 2004; Berk, 2004), or
deeper analysis of implications related to learning (Bartlett et al., 2020). Given the
aforementioned overall considerations, it comes as no surprise that, similarly to what
happened for binary classification, a plethora of performance metrics have been defined
and are currently in use for evaluating the quality of a regression model (Shcherbakov et al.,
2013; Hyndman & Koehler, 2006; Botchkarev, 2018b, Botchkarev, 2018a, Botchkarev, 2019).
The parallel with classification goes even further: in the scientific community, a shared
consensus on a preferential metric is indeed far from being reached, concurring to making
comparison of methods and results a daunting task.
The present study provides a contribute towards the detection of critical factors in the
choice of a suitable performance metric in regression analysis, through a comparative
overview of two measures of current widespread use, namely the coefficient of
determination and the symmetric mean absolute percentage error.
Indeed, despite the lack of a concerted standard, a set of well established and preferred
metrics does exist and we believe that, as primus inter pares, the coefficient of
determination R-squared deserves a major role. The coefficient of determination is also
known as R-squared or R2 in the scientific literature. For consistency, we will use all these
three names interchangeably in this study.
Introduced by Wright (1921) and generally indicated by R2, its original formulation
quantifies how much the dependent variable is determined by the independent variables,
in terms of proportion of variance. Again, given the age and diffusion of R2, a wealth of
studies about it has populated the scientific literature of the last century, from general
references detailing definition and characteristics (Di Bucchianico, 2008; Barrett, 2000;
Brown, 2009; Barrett, 1974), to more refined interpretative works (Saunders, Russell &
Crabb, 2012; Hahn, 1973; Nagelkerke, 1991; Ozer, 1985; Cornell & Berger, 1987; Quinino,
Reis & Bessegato, 2013); efforts have been dedicated to the treatment of particular cases
(Allen, 1997; Blomquist, 1980; Piepho, 2019; Srivastava, Srivastava & Ullah, 1995;
Dougherty, Kim & Chen, 2000; Cox & Wermuth, 1992; Zhang, 2017; Nakagawa, Johnson &
METHODS
In this section, we first introduce the mathematical background of the analyzed rates
(“Mathematical Background”), then report some relevant information about the
coefficient of determination and SMAPE (“R-squared and SMAPE”).
Mathematical background
In the following formulas, Xi is the predicted ith value, and the Yi element is the actual ith
value. The regression method predicts the Xi element for the corresponding Yi element of
the ground truth dataset. Define two constants: the mean of the true values
Xm
¼ 1
Y Yi (1)
m i¼1
1X m
MSE ¼ ðXi Yi Þ2 (4)
m i¼1
1X m
MAE ¼ jXi Yi j (6)
m i¼1
100% X
m
jXi Yi j
SMAPE ¼ (8)
m i¼1 ðjXi j þ jYi jÞ=2
R2 ≈ 10−8 .
R2 < 0: This case is only possible with linear regression when either the intercept or the
slope are constrained so that the "best-fit" line (given the constraint) fits worse than a
horizontal line, for instance if the regression line (hyperplane) does not follow the data
(CrossValidated, 2011b). With nonlinear regression, the R-squared can be negative
whenever the best-fit model (given the chosen equation, and its constraints, if any) fits the
data worse than a horizontal line. Finally, negative R2 might also occur when omitting
a constant from the equation, that is, forcing the regression line to go through the
point (0,0).
A final note. The behavior of the coefficient of determination is rather independent
from the linearity of the regression fitting model: R2 can be very low even for completely
linear model, and vice versa, a high R2 can occur even when the model is noticeably non-
linear. In particular, a good global R2 can be split in several local models with low R2
(CrossValidated, 2011a).
SMAPE
By definition, SMAPE values range between 0% and 200%, where the following holds in
the two extreme cases:
SMAPE = 0: The best case occurs when SMAPE vanishes, that is when
100% X
m
jXi Yi j
¼0
m i¼1 ðjXi j þ jYi jÞ=2
equivalent to
X
m
jXi Yi j
¼0
i¼1
ðjXi j þ jYi jÞ=2
equivalent to
By the triangle inequality |a + c| ≤ |a| + | c| computed for b = −c, we have that |a – b| ≤ |a|
fjabj
+ |b| and thus jajþjbj1. This yields that SMAPE = 2 if jXjXi jþjY
i Yi j
ij
¼ 1 for all i = 1,…,m. Thus we
jabj
reduced to compute when nða; bÞ ¼ jajþjbj ¼ 1: we analyse now all possible cases, also
considering the symmetry of the relation with respect to a and b, ξ(a,b) = ξ(b,a).
j0bj
If a = 0, nð0; bÞ ¼ j0jþjbj ¼ 1 if b = 0.
Now suppose that a,b > 0: ξ(a,a) = 0, so we can suppose a > b, thus a = b + ε, with a,b,ε > 0.
e
Then nða; bÞ ¼ nðb þ e; eÞ ¼ 2bþe < 1. Same happens when a,b < 0: thus, if ground truth
points and the prediction points have the same sign, SMAPE will never reach its maximum value.
Finally, suppose that a and b have opposite sign, for instance a > 0 and b < 0. Then
jaþcj
b = −c, for c > 0 and thus nða; bÞ ¼ nða; cÞ ¼ jajþjcj ¼ aþcaþc ¼ 1.
Summarising, SMAPE reaches its worst value 200% if
Xi· Yi<0 for all i = 1,…,m, that is, ground truth and prediction always have opposite sign,
regardless of their values.
For instance, if the ground truth points are (1, −2, 3, −4, 5, −6, 7, −8, 9, −10) , any prediction
vector with all opposite signs (for example, (−307.18, 636.16, −469.99, 671.53, −180.55,
838.23, −979.18 , 455.16, −8.32, 366.80) ) will result in a SMAPE metric reaching 200%.
Explained the extreme cases of R-squared and SMAPE, in the next section we illustrate
some significant, informative use cases where these two rates generate discordant outcomes.
so that REAL and PREDj coincides apart from the first j points 1, 6, 11,… congruent
to 1 modulo 5 that are set to 0. Then, for each 5 ≤ j ≤ 20, compute R2 and cnSMAPE (Table 1).
Both measures decrease with the increasing number of non-matching points p5k + 1 = 0,
but cnSMAPE decreases linearly, while R2 goes down much faster, better showing the
growing unreliability of the predicted regression. At the end of the process, j = 20 points
out of 100 are wrong, but still cnSMAPE is as high as 0.80, while R2 is 0.236, correctly
declaring PRED20 a very weak prediction set.
UC2 use case
In a second example, consider again the same REAL dataset and define the three
predicting sets
PREDstart ¼ fpsi : 1 i 100g
ri for i 10
psi ¼
0 for i , 10
PREDmiddle ¼ fpmi : 1 i 100g
ri for i 50 and i 61
pm ¼
i 0 for 51 i 60
PREDend ¼ fpei : 1 i 100g
ri for i 90
pei ¼
0 for i 91
In all the three cases start, middle, end the predicting set coincides with REAL up to 10
points that are set to zero, at the beginning, in the middle and at the end of the prediction,
respectively. Interestingly, cnSMAPE is 0.9 in all the three cases, showing that SMAPE
is sensible only to the number of non-matching points, and not to the magnitude of the
predicting error. R2 instead correctly decreases when the zeroed sequence of points is
further away in the prediction and thus farthest away from the actual values: R2 is 0.995 for
PREDstart, 0.6293 for PREDmiddle and −0.0955 for PREDend.
UC3 use case
Consider now the as the ground truth the line y = x, and sample the set T including
twenty positive integer points T = {ti = (xi,yTi) = (i,i) 1 ≤ i ≤ 20} on the line. Define REAL =
{ri = (xi,yRi) = (i,i + N(i)) 1 ≤ i ≤ 20} as the same points of T with a small amount of noise N
(i) on the y axes, so that ri are close but not lying on the y = x straight line. Consider now
two predicting regression models:
Clearly, pwi coincides with ri for 1 ≤ i ≤ 10, but ||pwi − ri|| becomes very large for i ≥ 11.
On the other hand ti ≠ ri for all i’s, but ||ti − ri|| is always very small. Compute now the two
measures R2 and cnSMAPE on the first N points i = 1, …, N for 2 ≤ N ≤ 20 of the two
different regression models c and w with respect to the ground truth set REAL (Table 2).
For the correct regression model, both measures are correctly showing good results. For
the wrong model, both measures are optimal for the first 10 points, where the prediction
exactly matches the actual values; after that, R2 rapidly decreases supporting the
inconsistency of the model, while cnSMAPE is not affected that much, arriving for N = 20
to a value 1/2 as a minimum, even if the model is clearly very bad in prediction.
To compare the values of the coefficient of determination and cnSMAPE in the same
range, we consider only the cases when R-squared is greater or equal to zero, and we call it
non-negative R-squared. We reported the results in Fig. 1.
As clearly observable in the plot Fig. 1, there are a number of points where cnSMAPE
has a high value (between 0.6 and 1) but R-squared had value 0: in these cases, the
coefficient of determination and cnSMAPE give discordant outcomes. One of these
cases, for example, is the regression where the predicted values have values (1, 2, 3, 5, 2) ,
R2 = 0, and cnSMAPE = 0.89.
In this example, cnSMAPE has a very high value, meaning that the prediction is 89%
correct, while R2 is equal to zero. The regression correctly predicts the first three points
(1, 2, 3) , but fails to classify the forth element (4 is wrongly predicted as 5), and the
fifth element (5 is mistakenly labeled as 2). The coefficient of determination assigns a bad
outcome to this regression because it fails to correctly classify the only members of the
4 and 5 classes. Diversely, SMAPE assigns a good outcome to this prediction because the
variance between the actual values and the predicted values is low, in proportion to the
overall mean of the values.
Faced with this situation, we consider the outcome of the coefficient of determination
more reliable and trustworthy: similarly to the Matthews correlation coefficient (MCC)
Medical scenarios
To further investigate the behavior of R-squared, MAE, MAPE, MSE, RMSE and SMAPE,
we employed these rates to a regression analysis applied to two real biomedical
applications.
Hepatitis dataset
We trained and applied several machine learning regression methods on the
Lichtinghagen dataset (Lichtinghagen et al., 2013; Hoffmann et al., 2018), which consists of
electronic health records of 615 individuals including healthy controls and patients
diagnosed with cirrhosis, fibrosis, and hepatitis. This dataset has 13 features, including a
numerical variable stating the diagnosis of the patient, and is publicly available in the
University of California Irvine Machine Learning Repository (2020). There are 540 healthy
controls (87.8%) and 75 patients diagnosed with hepatitis C (12.2%). Among the 75
patients diagnosed with hepatitis C, there are: 24 with only hepatitis C (3.9%); 21 with
hepatitis C and liver fibrosis (3.41%); and 30 with hepatitis C, liver fibrosis, and cirrhosis
(4.88%).
Obesity dataset
To further verify the effect of the regression rates, we applied the data mining methods
to another medical dataset made of electronic health records of young patients with obesity
(Palechor & De-La-Hoz-Manotas, 2019, De-La-Hoz-Correa et al., 2019). This dataset is
publicly available in the University of California Irvine Machine Learning Repository (2019)
too, and contains data of 2,111 individuals, with 17 variables for each of them. A variable
called NObeyesdad indicates the obesity level of each subject, and can be employed as a
regression target. In this dataset, there are 272 children with insufficient weight (12.88%),
287 children with normal weight (13.6%), 351 children with obesity type I (16.63%),
297 children with obesity type II (14.07%), 324 children with obesity type III (15.35%),
290 children with overweight level I (13.74%), and 290 children with overweight
level II (13.74%). The original curators synthetically generated part of this dataset
(Palechor & De-La-Hoz-Manotas, 2019, De-La-Hoz-Correa et al., 2019).
Methods
For the regression analysis, we employed the same machine learning methods two of us
authors used in a previous analysis (Chicco & Jurman, 2021): Linear Regression (Montgomery,
Peck & Vining, 2021), Decision Trees (Rokach & Maimon, 2005), and Random Forests
(Breiman, 2001), all implemented and executed in the R programming language (Ihaka &
Gentleman, 1996). For each method execution, we first shuffled the patients data, and then we
randomly selected 80% of the data elements for the training set and used the remaining
20% for the test set. We trained each method model on the training set, applied the trained
model to the test set, and saved the regression results measured through R-squared, MAE,
MAPE, MSE, RMSE, and SMAPE. For the hepatitis dataset , we imputed the missing data
with the Predictive Mean Matching (PMM) approach through the Multiple Imputation
by Chained Equations (MICE) method (Buuren & Groothuis-Oudshoorn, 2010). We ran 100
executions and reported the results means and the rankings based on the different rates in
Table 3 (hepatitis dataset) and in Table 4 (obesity dataset).
Hepatitis dataset results: different rate, different ranking
We measured the results obtained by these regression models on the Lichtinghagen
hepatitis dataset with all the rates analyzed in our study: R2, MAE, MAPE, RMSE, MSE and
SMAPE (lower part of Table 3).
These rates generate 3 different rankings. R2, MSE and RMSE share the same ranking
(Random Forests, Linear Regression and Decision Tree). SMAPE and MAPE share the
same ranking (Decision Tree, Random Forests and Linear Regression). MAE has its own
ranking (Random Forests, Decision Tree and Linear Regression).
It is also interesting to notice that these six rates select different methods as top
performing method. R2, MAE, MSE and RMSE indicate Random Forests as top
performing regression model, while SMAPE and MAPE select Decision Tree for the first
position in their rankings. The position of Linear Regression changes, too: on the second
rank for R2, MSE and RMSE, while on the last rank for MAE, SMAPE and MAPE.
By comparing all these different standings, a machine learning practitioner could
wonder what is the most suitable rate to choose, to understand how the regression
experiments actually went and which method outperformed the others. As explained
earlier, we suggest the readers to focus on the ranking generated by the coefficient of
determination, because it is the only metric that considers the distribution of all the ground
truth values, and generates a high score only if the regression correctly predict most of the
values of each ground truth category. Additionally, the fact that the ranking indicated
by R-squared (Random Forests, Linear Regression and Decision Tree) was the same
standing generated by 3 rates out of 6 suggests that it is the most informative one (Table 3).
Hepatitis dataset results: R2 provides the most informative outcome
Another interesting aspect of these results on the hepatitis dataset regards the
comparison between coefficient of determination and SMAPE (Table 3). We do not
compare the standing of R-squared with MAE, MSE, RMSE, and MAPE because these four
rates can have infinite positive values and, as mentioned earlier, this aspect makes it
impossible to detect the quality of a regression from a single score of these rates.
R-squared indicates a very good result for Random Forests (R2 = 0.756), and good
results for Linear Regression (R2 = 0.535) and Decision Tree (R2 = 0.423). On the contrary,
SMAPE generates an excellent result for Decision Tree (SMAPE = 0.073), meaning almost
perfect prediction, and poor results for Random Forests (SMAPE = 1.808) and Linear
Regression (SMAPE = 1.840), very close to the upper bound (SMAPE = 2) representing the
worst possible regression.
These values mean that the coefficient of determination and SMAPE generate
discordant outcomes for these two methods: for R-squared, Random Forests made a very
good regression and Decision Tree made a good one; for SMAPE, instead, Random Forests
made a catastrophic regression and Decision Tree made an almost perfect one. At this
point, a practitioner could wonder which algorithm between Random Forests and
Decision Trees made the better regression. Checking the standings of the other rates, we
clearly see that Random Forests resulted being the top model for 4 rates out of 6, while
Decision Tree resulted being the worst model for 3 rates out of 6. This information
confirms that the ranking of R-squared is more reliable than the one of SMAPE (Table 3).
Obesity dataset results: agreement between rankings, except for SMAPE
Differently from the rankings generated on the hepatitis dataset, the rankings produced
on the obesity dataset are more concordant (Table 4). Actually, the ranking of the
CONCLUSIONS
Even if regression analysis makes a big chunk of the whole machine learning and
computational statistics domains, no consensus has been reached on a unified prefered rate
to evaluate regression analyses yet. In this study, we compared several statistical rates
commonly employed in the scientific literature for regression task evaluation, and
described the advantages of R-squared over SMAPE, MAPE, MAE, MSE and RMSE.
Despite the fact that MAPE, MAE, MSE and RMSE are commonly used in machine
learning studies , we showed that it is impossible to detect the quality of the performance of
a regression method by just looking at their singular values. An MAPE of 0.7 alone, for
example, fails to communicate if the regression algorithm performed mainly correctly
or poorly. This flaw left room only for R2 and SMAPE. The first one has negative values if
the regression performed poorly, and values between 0 and 1 (included) if the regression
was good. A positive value of R-squared can be considered similar to percentage of
correctness obtained by the regression. SMAPE, instead, has the value 0 as best value for
perfect regressions and has the value 2 as worst value for disastrous ones.
In our study, we showed with several use cases and examples that R2 is more truthful
and informative than SMAPE: R-squared, in fact, generates a high score only if the
regression correctly predicted most of the ground truth elements for each ground truth
group, considering their distribution. SMAPE, instead, focuses on the relative distance
between each predicted value and its corresponding ground truth element, without
considering their distribution. In the present study SMAPE turned out to perform bad in
identifying bad regression models.
A limitation of R2 arises in the negative space. When R-squared has negative values,
it indicates that the model performed poorly but it is impossible to know how bad a
model performed. For example, an R-squared equal to −0.5 alone does not say much about
the quality of the model, because the lower bound is −∞. Differently from SMAPE that
LIST OF ABBREVIATIONS
COVID-19 Coronavirus disease 2019
DT Decision Trees
LR Linear Regression
MAE Mean absolute error
MAPE Mean absolute percentage error
MSE Mean square error
R2 R-squared, coefficient of determination
RF Random Forests
RMSE root mean square error
SMAPE symmetric mean absolute percentage error
ACKNOWLEDGEMENTS
The authors thank David Reeves (the University of Manchester) for his useful advice.
Funding
The authors received no funding for this work.
Competing Interests
Davide Chicco is an Academic Editor for PeerJ Computer Science.
Data Availability
The following information was supplied regarding data availability:
The software code is available at GitHub: [Link]
versus_other_regression_rates.
Supplemental Information
Supplemental information for this article can be found online at [Link]
peerj-cs.623#supplemental-information.
REFERENCES
Allen DM. 1971. Mean square error of prediction as a criterion for selecting variables.
Technometrics 13(3):469–475.
Allen MP. 1997. The coefficient of determination in multiple regression. In: Understanding
Regression Analysis. Boston: Springer, 91–95.
Allen MP. 2004. Understanding regression analysis. Berlin, Germany: Springer Science & Business
Media.
Altman N, Krzywinski M. 2015. Simple linear regression. Nature Methods 12(11):999–1000.
Applegate RA, Ballentine C, Gross H, Sarver EJ, Sarver CA. 2003. Visual acuity as a function of
Zernike mode and level of root mean square error. Optometry and Vision Science 80(2):97–105.
Armstrong JS. 1985. Long-range forecasting: from crystal ball to computer. Hoboken: John Wiley &
Sons.
Armstrong JS, Collopy F. 1992. Error measures for generalizing about forecasting methods:
empirical comparisons. International Journal of Forecasting 08:69–80.
Barrett JP. 1974. The coefficient of determination—some limitations. The American Statistician
28(1):19–20.
Barrett GB. 2000. The coefficient of determination: understanding r2 and R2. The Mathematics
Teacher 93(3):230–234.
Bartlett PL, Long PM, Lugosi G, Tsigler A. 2020. Benign overfitting in linear regression.
Proceedings of the National Academy of Sciences of the USA 117(48):30063–30070
DOI 10.1073/pnas.1907378117.
Berk RA. 2004. Regression analysis: a constructive critique. Vol. 11. Thousand Oaks: Sage.
Berk RA. 2020. Statistical learning as a regression problem. In: Statistical Learning from a
Regression Perspective. Berlin: Springer International Publishing, 1–72.
Blomquist NS. 1980. A note on the use of the coefficient of determination. Scandinavian Journal of
Economics 82(3):409–412 DOI 10.2307/3439750.