Last active
December 20, 2018 23:34
-
-
Save GermanCM/a6d072d88defd3a2f605ca9cfcb551c5 to your computer and use it in GitHub Desktop.
Features normalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def normalize_features(df): | |
""" | |
Normalize the features in the data set. | |
Returns the normalized values, mean and standard deviation for each feature | |
""" | |
mu = df.mean() | |
sigma = df.std() | |
if (sigma == 0).any(): | |
raise Exception("One or more features had the same value for all samples, so could not be normalized. Please do not include features with only a single value in your model") | |
df_normalized = (df - df.mean()) / df.std() | |
return df_normalized, mu, sigma |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment