1
$\begingroup$

I build an LSTM model on a standardized dataset using sklearn's MinMaxScaler. All values of the dataset are between 0 and 1. Features and target variables were standardized between 0 and 1. I achieve an mse of around 0.02 .

Now this mse is valid for the standardized dataset. What would the mse be on the original scale? Let's say the original scale is dollars. What would an mse of 0.02 be on the original scale in dollars?

$\endgroup$

1 Answer 1

2
$\begingroup$

TLDR: You need to multiply your scaled mse by $(max - min)^2$.

Let's give our values some names: Let $y_n$ denote the dependant variable, $m$ be the number of observations \begin{align*} & min := \min\limits_{n} y_n, \\ & max := \max\limits_{n} y_n \end{align*} and let $p_n'$ be the (scaled) predicted value for $y_n$. The scaled value $y_n'$ for $y_n$ is given by $$ y_n' = \frac{y - min}{max - min}. $$ So scaled mse that you calculated is given by $$ 0.02 = mse_{\text{scaled}} = \frac1m \sum\limits_n |y_n' - p_n'|^2 = \frac1m \sum\limits_n |\frac{y - min}{max - min} - p_n'|. $$ In order to get the true mse, you want to rescale $y_n'$ to $y_n$ and $p_n'$ to $p_n$ using $$ p_n' = \frac{p_n - min}{max - min}.$$ This gives us \begin{align*} mse_{\text{scaled}} & = \frac1m \sum\limits_{n} |\frac{y_n - min}{max - min} - \frac{p_n - min}{max - min}|^2 \\ & = \frac1m \sum\limits_{n} |\frac{y_n}{max - min} - \frac{min}{max - min} - \frac{p_n}{max - min} + \frac{min}{max - min}|^2 \\ & = \frac1m \sum\limits_{n} |\frac{y_n}{max - min} - \frac{p_n}{max - min}|^2 \\ & = \frac{1}{(max - min)^2} \frac1m \sum\limits_{n} |y_n - p_n|^2. \end{align*} Rearraging this gives us $$ mse_{\text{original}} = \frac1m \sum\limits_{n} |y_n - p_n|^2 = (max - min)^2 mse_{\text{scaled}}. $$

However, in general, it is better to first rescale your values and then take the mse because you lose interpretability and, as you see, it is more difficult to rescale the mse than to rescale the predicted values.

$\endgroup$
4
  • 1
    $\begingroup$ Thanks for your answer. By using sklearn's MinMaxScaler this would mean that I make an inverse transformation: mse = 0.02 inverse_scaler = MinMaxScaler() inverse_scaler.min_,inverse_scaler.scale_ = scaler.min_[0], scaler.scale_[0] mse_inverse = inverse_scaler.inverse_transform([[mse]]) . However this gives me a huge number and that would mean that the model is does not predict well at all, but I get forecasts that make sense $\endgroup$
    – eetiaro
    Commented Jun 3, 2020 at 8:16
  • $\begingroup$ The inverse transformation also adds $min$ in addition to multiplying by $max - min$. $\endgroup$ Commented Jun 3, 2020 at 8:28
  • $\begingroup$ I see... Could you give an example on how to inverse_scale mse by using scikit's MinMaxScaler? $\endgroup$
    – eetiaro
    Commented Jun 3, 2020 at 8:37
  • $\begingroup$ You don't need to use a scikit function, you can just multiply your value (0.02) by $(max - min)^2$ using the maximum and minimum value of your unscaled dependant variable. So if you have values from 10 to 100, you would get $0.02 * (100-10)^2 = 162$. $\endgroup$ Commented Jun 3, 2020 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.