Skip to content

Instantly share code, notes, and snippets.

@crawles
Created July 17, 2018 17:46
Show Gist options
  • Save crawles/e3f47e10775e9650c2e2ba6bb8dd7f13 to your computer and use it in GitHub Desktop.
Save crawles/e3f47e10775e9650c2e2ba6bb8dd7f13 to your computer and use it in GitHub Desktop.
def get_normalization_parameters(traindf, features):
"""Get the normalization parameters (E.g., mean, std) for traindf for
features. We will use these parameters for training, eval, and serving."""
def _z_score_params(column):
mean = traindf[column].mean()
std = traindf[column].std()
return {'mean': mean, 'std': std}
normalization_parameters = {}
for column in features:
normalization_parameters[column] = _z_score_params(column)
return normalization_parameters
NUMERIC_FEATURES = ['housing_median_age', 'total_rooms', 'total_bedrooms',
'population', 'households', 'median_income']
normalization_parameters = get_normalization_parameters(traindf, NUMERIC_FEATURES)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment