R2Score< AdjustedR2 > Class Template Reference

The R2 Score is a metric of performance for regression algorithms that represents the proportion of variance (here y) that has been explained by the independent variables in the model. More...

Static Public Member Functions

template
<
typename
MLAlgorithm
,
typename
DataType
,
typename
ResponsesType
>
static double Evaluate (MLAlgorithm &model, const DataType &data, const ResponsesType &responses)
 Run prediction and calculate the R squared or Adjusted R squared error. More...

 

Static Public Attributes

static const bool NeedsMinimization = false
 Information for hyper-parameter tuning code. More...

 

Detailed Description


template<bool AdjustedR2>
class mlpack::cv::R2Score< AdjustedR2 >

The R2 Score is a metric of performance for regression algorithms that represents the proportion of variance (here y) that has been explained by the independent variables in the model.

It provides an indication of goodness of fit and therefore a measure of how well unseen samples are likely to be predicted by the model, through the proportion of explained variance. As R2 Score is dataset dependent it can have wide range of values. The best possible score is $R^2 =1.0$. Values of R2 outside the range 0 to 1 can occur when the model fits the data worse than a horizontal hyperplane. This would occur when the wrong model was chosen, or nonsensical constraints were applied by mistake. A model which predicts exactly the expected value of y, disregarding the input features, gets a R2 Score equals to 0.0. If a model predicts $ \hat{y}_i $ of the $ i $-th sample for a true $ y_i $ for total n samples, the R2 Score is calculated by

\begin{eqnarray*} R^{2} \left( y, \hat{y} \right) &=& 1-\frac{\sum_{i=1}^{n} \left( y_i - \hat{y_i} \right)^2 } {\sum_{i=1}^{n} \left( y_i - \bar{y}\right)^2}\\ \end{eqnarray*}

where $ \bar{y} = frac{1}{y}\sum_{i=1}^{n} y_i $. For example, a model having R2Score = 0.85, explains 85 % variability of the response data around its mean.

Template Parameters
AdjustedR2If true, then the Adjusted R2 score will be used. Otherwise, the regular R2 score is used.

Definition at line 51 of file r2_score.hpp.

Member Function Documentation

◆ Evaluate()

static double Evaluate ( MLAlgorithm &  model,
const DataType &  data,
const ResponsesType &  responses 
)
static

Run prediction and calculate the R squared or Adjusted R squared error.

Parameters
modelA regression model.
dataColumn-major data containing test items.
responsesGround truth (correct) target values for the test items, should be either a row vector or a column-major matrix.
Returns
calculated R2 Score.

Member Data Documentation

◆ NeedsMinimization

const bool NeedsMinimization = false
static

Information for hyper-parameter tuning code.

It indicates that we want to maximize the measurement.

Definition at line 72 of file r2_score.hpp.


The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/core/cv/metrics/r2_score.hpp