Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanfrisch/a1158ff9cf0d7c4ac996b4381084cb58 to your computer and use it in GitHub Desktop.
Save evanfrisch/a1158ff9cf0d7c4ac996b4381084cb58 to your computer and use it in GitHub Desktop.
def save_quantiles(self,dataframe,fields,filepath,quantiles=[0.02,0.1,0.25,0.5,0.75,0.9,0.98]):
"""Writes a JSON file containing quantile metrics for specified fields of the supplied H2O dataframe.
:param dataframe: the H2O dataframe
:param fields: the names of the fields for which quantile metrics will be computed
:param filepath: the path to the location where the JSON file will be stored
:param quantiles: the array of quantiles to compute (Default value = [0.02,0.1,0.25,0.5,0.75,0.9,0.98])
"""
df = dataframe.as_data_frame(use_pandas=True)
results = {}
for field in fields:
quantile_metrics = [round(df[field].quantile(q),1) for q in quantiles]
print("Quantile metrics for {}: {}".format(field, quantile_metrics))
results[field] = quantile_metrics
with open(filepath,'w') as f:
json.dump(results,f)
print("Saved quantile metrics to {}.".format(filepath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment