name
, an optional description
, and a script
that calculates the metric. Optionally, you can set a hidden
property to true to hide the metric from the UI.
Inside one metric, you can use another metric through the available object Metric
like this: Metric["licenses_to_renew"]
.
The most important part of the metric definition is the Javascript code. This script can use ES2023 JS syntax and it must implement a function body that returns a number representing the computed metric value. Within a script, the following functions and objects are available:
ds
anddsAll
: Accessors to the dataset used as input.dsAll
refers to the entire dataset, whileds
is affected by the applied selection. If no selection is made, both accessors refer to the same dataset.count(ds)
: A function that returns the number of rows in the dataset.where("queryString", () => { /* 'ds' accessor is a subset filtered by the query and the global selection */ })
: A function that applies a filter to theds
accessor. Note thatdsAll
remains unaffected. Multiplewhere
calls can be nested. See Advanced query filters for more information on query strings.Metrics
: You can reference another metrics within a metrics script using theMetrics
object, e.g.,Metrics["licenses_to_renew"]
.
- For a numerical column ‘sales’: ds.sales.sum or ds.sales.mean
- For a categorical column ‘department’: ds.department.uniqueValues
- For a text column ‘description’: ds.description.wordCount
- For a date column ‘order_date’: ds.order_date.min or ds.order_date.max
.nullRows
: Returns the number of null rows in the column..validRows
: Returns the number of non-null rows in the column.
.count
: Returns the number of non-null values in the column. If the column is a List this will count each element..sum
: Calculates the sum of all values in the column..stddev
: Calculates the standard deviation of the values in the column..variance
: Calculates the variance of the values in the column..mean
: Calculates the average of all values in the column..min
: Returns the minimum value in the column..p25
: Calculates the 25th percentile of the values in the column..p50
: Calculates the 50th percentile (median) of the values in the column..median
: An alias for.p50
, calculates the median of the values in the column..p75
: Calculates the 75th percentile of the values in the column..max
: Returns the maximum value in the column.
.count
: Returns the number of non-null values in the column. If the column is a List this will count each element..uniqueValues
: Returns the number of unique values in the column.
.wordCount
: Calculates the total number of words across all non-null rows in the column.
Usage
The following examples show how the step can be used in a recipe.Examples
Examples
Calculate the average order value on the selected rows
Inputs & Outputs
The following are the inputs expected by the step and the outputs it produces. These are generally columns (ds.first_name
), datasets (ds
or ds[["first_name", "last_name"]]
) or models (referenced
by name e.g. "churn-clf"
).
Inputs
Inputs
Dataset to be used for calculating metrics.
Outputs
Outputs
Configuration
The following parameters can be used to configure the behaviour of the step by including them in a json object as the last “input” to the step, i.e.step(..., {"param": "value", ...}) -> (output)
.
Parameters
Parameters
Metrics list.
The list of metrics to be calculated and displayed has the following properties:
- name: The ID for the metric. No duplicated names are allowed.
- description: An optional description of the metric.
- script: The javascript code that calculates the metric. The metric should return a number.
- hidden: A boolean that indicates whether the metric should be hidden. Useful for auxiliary metrics.
Array items
Array items
Metric name.
An ID for the metric. No duplicated names are allowed.
Metric description.
An optional description of the metric.
Metric script.
Hidden metric.
A boolean that indicates whether the metric should be hidden. Useful for auxiliary metrics.
Show difference.
Whether to show the difference between the metric of the selection and the metric of the total population.
This can be configured individually for each metric. If not specified, the global configuration will be used.Values must be one of the following:
ABSOLUTE
RELATIVE
Show difference.
Whether to show the difference between the metric of the selection and the metric of the total population.Values must be one of the following:
ABSOLUTE
RELATIVE