Question

I'm using Brain to train a neural network on a feature set that includes both positive and negative values. But Brain requires input values between 0 and 1. What's the best way to normalize my data?

Was it helpful?

Solution

This is called unity-based normalization. If you have a vector $X$, you can obtain a normalized version of it, say $Z$, by doing:

$$Z = \frac{X - \min(X)}{\max(X) - \min(X)}$$

OTHER TIPS

Find the largest positive number and the smallest (most negative) number in the array. Add the absolute value of the smallest (most negative) number to every value in the array. Divide each result by the difference between the largest and the smallest number.

say you have a vector/array of values v = [1, -2, 3]

minV = Math.min.apply(Math, v);;
for(var i=0; i<v.length; i++) {v[i] -= minV;}
maxV = Math.max.apply(Math, v);;
for(var i=0; i<v.length; i++) {v[i] /= ( maxV - minV );}

Output at the end will be v = [0.6, 0, 1]. Explanation:

  1. Pushing the entire range of values to start from 0, so that we have no negatives

  2. Dividing the values by ( max - min ) of range, so that max will be 1

Before you do that, you may want to check for outliers. Say 99% of the data lie in range (-5, 5), but one little guy takes a value of 25.0. Your normalized array would cluster around (0, 0.3), and that would cause problem for the neural net to learn.

Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top