-3

Value: 0.344 -0.124 0.880 0 0.910 -0.800

Kent Shikama
  • 3,910
  • 3
  • 22
  • 55
Suru
  • 9
  • 1
  • 6
  • I'm assuming the "Value: ..." is your input? Can you please specify what you would like your corresponding output to be? – Kent Shikama Dec 06 '19 at 06:54
  • yes, value is input. I want to normalize this input using standard deviation into (-3, -2,-1, 0, 1, 2, 3) – Suru Dec 09 '19 at 04:07

3 Answers3

0

You can try cut() function in R to divide values into intervals.

value <- c(0.344, -0.124, 0.880, 0, 0.910, -0.800)
value.normalized <- cut(
  x = value, breaks = seq(-1, 1, length.out = 8), 
  labels = -3:3, include.lowest = TRUE, right = TRUE
)

(value.normalized)
1  0  3  0  3  -3
Levels: -3 -2 -1 0 1 2 3
h45
  • 206
  • 1
  • 6
  • cut () function using standard deviation formula to normalize? – Suru Dec 09 '19 at 04:08
  • No. cut() breaks values into bins whose intervals as you have defined. The problems are: 1. You did not mention to use standard deviation in your question. 2. You mentioned intervals of a new bins (-3, -2, -1, 0, 1, 2, 3) instead of real number between {-3,3} as standard deviation will do. 3. Using standard deviation will not guarantee your numbers fall in the range of {-1,1} as contrast with your statement that your numbers lie in the range of {-1,1}. – h45 Dec 09 '19 at 07:01
0

You Can do something like this to normalize any data to given scale:

>>> Data = [0.9, 0.2, 0.3, 0.4]
>>> lower, upper =-3, 3
>>> Data_norm = [lower + (upper - lower) * x for x in Data]
>>> Data_norm
[2.4000000000000004, -1.7999999999999998, -1.2000000000000002, -0.5999999999999996]
0

Use sklearn.preprocessing.minmax_scale

In [1]: from sklearn.preprocessing import minmax_scale


In [2]: value = [0.344,-0.124,0.880,0,0.910,-0.800]


In [3]: in_range = [-1, 1]


In [4]: value_scaled = minmax_scale(value + in_range, feature_range=(-3,3))


In [5]: value_scaled[:-2]

Out[5]: array([ 1.032, -0.372,  2.64 ,  0.   ,  2.73 , -2.4  ])
fabda01
  • 3,384
  • 2
  • 31
  • 37