Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def normalization(x_train):
- '''
- apply normalization to the samples (x_train)
- returns a new array that has been properly normalized,
- also returns the mean and standard deviation per feature in the training set
- '''
- # >>> YOUR CODE STARTS HERE <<<
- x_train_normalized = np.empty(shape = x_train.shape)
- i = 0
- for features in x_train:
- normed = []
- feature_std = np.std(features, axis=0)
- feature_mean = np.mean(features, axis=0)
- for feature in features:
- normed.append((feature-feature_mean)/feature_std)
- x_train_normalized[i] = normed
- i+=1
- print(x_train_normalized)
- # array of normalized features
- mean = np.mean(x_train_normalized, axis=0) # array of mean value per feature
- std = np.std(x_train_normalized, axis=0) # array of std value per feature
- # >>> YOUR CODE ENDS HERE <<<
- return x_train_normalized, mean, std
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement