Spaces:
Sleeping
Sleeping
File size: 3,113 Bytes
ad8da65 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# Composing Functions (Advanced Usage) To see functions you can use with this syntax, checkout the {doc}`aggregation functions <aggregation_functions>` and the {doc}`transformation functions <transformation_functions>`. Any function with a parameter with the type signature `[string or nested]` is able to accept the following as a value: 1. a string constant that represents a property of the model 1. an object of the form: ```json { "alias_ref": "string", "nested_function": {"...": "..."} } ``` Only one of `alias_ref` or `nested_function` may be present at a time. See the following explanations of each. ## Alias References The `alias_ref` field allows specifying another selected column's alias to use as input to the function. This example uses an `alias_ref` to pull in another column to the `add` function: ```json { "select": [ { "function": "abs", "alias": "absLoan", "parameters": { "property": "loan" } }, { "function": "add", "alias": "plus2", "parameters": { "left": 2, "right": { "alias_ref": "absLoan" } } } ] } ``` This request returns: ```json { "query_result": [ { "absLoan": 55.45, "plus2": 57.45 } ] } ``` ## Nested Functions The `nested_function` field allows specifying another function definition to use as input. Here's an example of how to calculate absolute error for a regression model. In this example, we pass the nested `subtract` function as input to the `abs` function via the `nested_function` object for the `property` parameter of `abs`: ```json { "select": [ { "function": "abs", "alias": "abs_error", "parameters": { "property": { "nested_function": { "function": "subtract", "alias": "error", "parameters": { "left": "Predicted_FICO_Score", "right": { "alias_ref": "ground_truth" } } } } } }, { "property": "Predicted_FICO_Score" }, { "property": "Consumer_Credit_Score", "alias": "ground_truth" } ] } ``` This query returns: ```json { "query_result": [ { "Consumer_Credit_Score": 660, "Predicted_FICO_Score": 688.10004, "abs_error": 28.100040000000035 }, { "Consumer_Credit_Score": 663, "Predicted_FICO_Score": 681, "abs_error": 18 }, "..." ] } ``` ```{note} If you use the same function multiple times in a query, you need to give each one a distinct "alias". Otherwise, the names will conflict. ``` |