How to Normalize
Hello!
Normalization can refer to a bunch of somewhat different things.
Often it means you have a bunch of values, say 3, 5, and 7, and you want them all to be in the range of 0 to 1, but obvoiusly you want to keep their relative differences the same.
Here’s how you do it:
- find the sum of all your values, so in our case it would be 3 + 5 + 7 = 17
- divide each value by this sum, so our new values will be 3/17, 5/17, and 7/17.
Sometimes you want them to be in some range other than 0 to 1, for example, 0 to 10.
Here’s how you do it:
- find the sum of all your values, so in our case it would be 3 + 5 + 7 = 17
- divided each value by this sum, so our new values will be 3/17, 5/17, and 7/17.
- multiply each value by 10, so our new values will be 3/17 * 10, 5/17 * 10, and 7/17 * 10
Sometimes you want your values to be in some range that doesn’t start with 0, for example 4-10.
Here’s how you do it:
- find the sum, so again, we’d have 17
- divide each value by sum, so again, we’d have 3/17, 5/17 and 7/17
- multiply each value by your range, so in our case we’d multiply them by 10-4 = 6
- add the start of your range to each value, so in our case we’d add 4
That’s it, pretty easy! Here’s a python environment you can use to play around with normalization.
values = [3,5,7]
the_sum = sum(values)
# normalize them from 0-1
normalized1 = [v/the_sum for v in values]
# normalize them from 0 to 10
normalized2 = [v/the_sum * 10 for v in values]
# normalize them from 4 to 10
normalized3 = [v/the_sum * (10-4) + 4 for v in values]
# print all our results
print(normalized1)
print(normalized2)
print(normalized3)