I am using python preprocessing to scale my data. I used MinMaxScaler with parameters of feature_range=(-1, 1). But this returns data in a range of [-1,1]. I need data in a range of (-1,1). How can I do it?
This seems like an odd question, because in general scaling is inclusive - by definition, scaling to (lower_bound, upper_bound)
means the smallest thing in the data set gets mapped to lower_bound
and the largest to upper_bound
, so it's sort of contradictory to say you want an exclusive range, because then the "maximum" of the range is not mapped to by anything in the data.
This is why there is no functionality to do so - scaling to a range is always inclusive. I would consider carefully why you need an exclusive scaling - i.e. whether you really do.
That said, here are some ideas, which are both mathematically dubious (they will introduce some error):
1.) feature_range = (-1 + eps, 1 - eps)
: where eps = .000000000000001
or a suitably small number. Narrowing the acceptable range by an arbitrarily small number approximates an exclusive range as the number eps
approaches 0.
2.)
for entry in data:
if entry is 1:
entry = entry - eps
else if entry is -1:
entry = entry + eps
This is even more mathematically dubious because it will artificially "push in" the ends of your distribution, but it will leave the mapping unchanged for every value greater than (-1 + eps)
and less than (1 - eps)
.