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
  • 3
    You would need to save the min and max to be able to transform the result back to the original scale. Commented Jul 26, 2017 at 20:20
  • Would the answer be then: Predicted_Original_Scaled_Number = Predicted_Feature_Scaled_Number * (Max_Original - Min_Original) + Min_Original? Commented Jul 26, 2017 at 20:26
  • 1
    That's exactly it Commented Jul 26, 2017 at 20:34
  • Awesome thank you. Would you mind putting that as an answer to give you credit? Commented Jul 26, 2017 at 20:35

1 Answer 1

2

Sure. Might as well put it in a function although you did provide the answer yourself.

This one should be given the predicted value and the original vector

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

or if you computed and kept the minimum and maximum then

backtransform2 <- function(value, min, max) { value * (max - min) + min }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.