Created
October 31, 2017 01:24
-
-
Save evanfrisch/a1158ff9cf0d7c4ac996b4381084cb58 to your computer and use it in GitHub Desktop.
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 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