The CustomMetricArgumentParser class wraps the standard argparser.ArgumentParser. This class provides convenience functions to allow reading values from the environment or normal argument parsing. When CustomMetricArgumentParser.parse_args() is called, it checks for missing values.
The log_manager provides a set of functions to help with logging. The DMM library and the DataRobot public API client use standard Python logging primitives. A complete list of log classes with their current levels is available using get_log_levels(). The initialize_loggers() function initializes all loggers:
The following snippet shows how to set up your runtime environment using the previously mentioned classes:
importsysfromdmmimportCustomMetricArgumentParserfromdmm.log_managerimportinitialize_loggersparser=CustomMetricArgumentParser(description="My new custom metric")parser.add_base_args()# adds standard arguments# Add more with standard ArgumentParser primitives, or some convenience functions such as add_environment_arg()# Parse the program arguments (if any) to an argparse.Namespace.args=parser.parse_args(sys.argv[1:])# Initialize the logging based on the 'LOG' environment variable, or the --log optioninitialize_loggers(args.log)
The standard/base arguments include the following:
Argument
Description
BASE_URL
The URL of the public API.
API_KEY
The API token used for authentication to the server located at BASE_URL.
DEPLOYMENT_ID
The deployment ID from the application.
CUSTOM_METRIC_ID
The custom metric ID from the application.
DRY_RUN
The flag to indicate whether to report the custom metric result to the deployment. With the DRY_RUN runtime parameter set to 1, the run is a test run and does not report metric data.
START_TS
The start of the time range for metric calculation.
END_TS
The end of the time for metric calculation.
MAX_ROWS
The maximum number of prediction rows to process.
LOG
The initialization of logging—defaults to setting all dmm and datarobot modules to WARNING.
The following is an example of the help provided using CustomMetricArgumentParser:
During development, it is common to run your code over the same data multiple times to see how changes impact the results. The save_to_csv() utility allows you to save your results to a CSV file, so you can compare the results between successive runs on the same data.