In an ideal world your train and test data should be from the same distribution. However obviously that is not always possible. E.g. with time series of prices for something, inflation means the distribution is always shifting right, but generally you want test data to come after training data.
There are a few things you can do, depending on what kind of data it is.
Let's get the ugly one out of the way first: you can clip all future inputs to the range of values seen in the training data. I'd only do this if you are actually hitting problems; as others have said, normally it doesn't break anything.
Or, if MinMaxScaler
is giving problems, consider using StandardScaler
instead.
If you have domain knowledge you might be able to specify the theoretical min/max, rather than learning it from the training data. E.g. maybe a value will always be between 0 and 100, or between -1.0 and +1.0.
If you know the conditions that cause the extreme values, you can actually add them to the training data. For instance in a NLP sentiment model, I could create artificial sentences that demonstrate the extreme emotions.
For data that changes over time, you might be able to use a domain-specific normalization. For instance, for a price database I could change absolute values to be a value relative to what they were a year ago. Train, test, and future values all ought to be in the same distribution now.
Standard scalers like Scikit MinMax don't support [adding wiggle room]
With MinMaxScaler
you could set feature_range
to 0.01 to 0.99, instead of the default 0.0 to 1.0.