문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 datascience.stackexchange
scroll top