1

I have a general question about feature scaling in linear regression.

I have a dataset that is two years worth of data. The first year's worth of data for a specific column is completely different than the 2nd year's. I am assuming that maybe there were different attributes associated with calculating the 1st year's variable vs. the 2nd year.

Anyway, here is what the dataset looks like. I will show the first 6 rows of each year:

Date             Col1
2015-01-01       1500
2015-01-02       1432
2015-01-03       1234
2015-01-04       1324
2015-01-05       1532
2015-01-06       1424
.
.
.
2016-01-01         35
2016-01-02         31
2016-01-03         29
2016-01-04         19
2016-01-05         22
2016-01-06         32

When I want to forecast this dataset, obviously it is going to forecast results in the negative but in reality the data has just been rescaled in some way.

If I apply feature scaling as so, how do I revert back to my original dataset to make a forecast?

normalize <- function(x){
  return((x-min(x)) / (max(x)-min(x)))
}

scaled_data <- 
  df %>%
  group_by(Date %>%
  mutate(NORMALIZED = normalize(Col1))
4

1 回答 1

2

当然。尽管您确实自己提供了答案,但不妨将它放在一个函数中。

这个要给定预测值和原向量

backtransform <- function(value, x) { value * (max(x) - min(x)) + min(x) }

或者如果您计算并保持最小值和最大值,那么

backtransform2 <- function(value, min, max) { value * (max - min) + min }
于 2017-07-26T20:43:10.010 回答