|
| 1 | +--- |
| 2 | +title: Trigger batch inference with trained model |
| 3 | +titleSuffix: Azure Cognitive Services |
| 4 | +description: Trigger batch inference with trained model |
| 5 | +services: cognitive-services |
| 6 | +author: mrbullwinkle |
| 7 | +manager: nitinme |
| 8 | +ms.service: cognitive-services |
| 9 | +ms.subservice: anomaly-detector |
| 10 | +ms.topic: conceptual |
| 11 | +ms.date: 11/01/2022 |
| 12 | +ms.author: mbullwin |
| 13 | +--- |
| 14 | + |
| 15 | +# Trigger batch inference with trained model |
| 16 | + |
| 17 | +You could choose the batch inference API, or the streaming inference API for detection. |
| 18 | + |
| 19 | +| Batch inference API | Streaming inference API | |
| 20 | +| ------------- | ---------------- | |
| 21 | +| More suitable for batch use cases when customers don’t need to get inference results immediately and want to detect anomalies and get results over a longer time period.| When customers want to get inference immediately and want to detect multivariate anomalies in real-time, this API is recommended. Also suitable for customers having difficulties conducting the previous compressing and uploading process for inference. | |
| 22 | + |
| 23 | +|API Name| Method | Path | Description | |
| 24 | +| ------ | ---- | ----------- | ------ | |
| 25 | +|**Batch Inference**| POST | `{endpoint}`/anomalydetector/v1.1/multivariate/models/`{modelId}`: detect-batch | Trigger an asynchronous inference with `modelId`, which works in a batch scenario | |
| 26 | +|**Get Batch Inference Results**| GET | `{endpoint}`/anomalydetector/v1.1/multivariate/detect-batch/`{resultId}` | Get batch inference results with `resultId` | |
| 27 | +|**Streaming Inference**| POST | `{endpoint}`/anomalydetector/v1.1/multivariate/models/`{modelId}`: detect-last | Trigger a synchronous inference with `modelId`, which works in a streaming scenario | |
| 28 | + |
| 29 | +## Trigger a batch inference |
| 30 | + |
| 31 | +To perform batch inference, provide the blob URL containing the inference data, the start time, and end time. For inference data volume, at least `1 sliding window` length and at most **20000** timestamps. |
| 32 | + |
| 33 | +This inference is asynchronous, so the results aren't returned immediately. Notice that you need to save in a variable the link of the results in the **response header** which contains the `resultId`, so that you may know where to get the results afterwards. |
| 34 | + |
| 35 | +Failures are usually caused by model issues or data issues. You can't perform inference if the model isn't ready or the data link is invalid. Make sure that the training data and inference data are consistent, meaning they should be **exactly** the same variables but with different timestamps. More variables, fewer variables, or inference with a different set of variables won't pass the data verification phase and errors will occur. Data verification is deferred so that you'll get error messages only when you query the results. |
| 36 | + |
| 37 | +### Request |
| 38 | + |
| 39 | +A sample request: |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "dataSource": "{{dataSource}}", |
| 44 | + "topContributorCount": 3, |
| 45 | + "startTime": "2021-01-02T12:00:00Z", |
| 46 | + "endTime": "2021-01-03T00:00:00Z" |
| 47 | +} |
| 48 | +``` |
| 49 | +#### Required parameters |
| 50 | + |
| 51 | +* **dataSource**: This is the Blob URL that linked to your folder or CSV file located in Azure Blob Storage. The schema should be the same as your training data, either OneTable or MultiTable, and the variable number and name should be exactly the same as well. |
| 52 | +* **startTime**: The start time of data used for inference. If it's earlier than the actual earliest timestamp in the data, the actual earliest timestamp will be used as the starting point. |
| 53 | +* **endTime**: The end time of data used for inference, which must be later than or equal to `startTime`. If `endTime` is later than the actual latest timestamp in the data, the actual latest timestamp will be used as the ending point. |
| 54 | + |
| 55 | +#### Optional parameters |
| 56 | + |
| 57 | +* **topContributorCount**: This is a number that you could specify N from **1 to 30**, which will give you the details of top N contributed variables in the anomaly results. For example, if you have 100 variables in the model, but you only care the top five contributed variables in detection results, then you should fill this field with 5. The default number is **10**. |
| 58 | + |
| 59 | +### Response |
| 60 | + |
| 61 | +A sample response: |
| 62 | + |
| 63 | +```json |
| 64 | +{ |
| 65 | + "resultId": "aaaaaaaa-5555-1111-85bb-36f8cdfb3365", |
| 66 | + "summary": { |
| 67 | + "status": "CREATED", |
| 68 | + "errors": [], |
| 69 | + "variableStates": [], |
| 70 | + "setupInfo": { |
| 71 | + "dataSource": "https://mvaddataset.blob.core.windows.net/sample-onetable/sample_data_5_3000.csv", |
| 72 | + "topContributorCount": 3, |
| 73 | + "startTime": "2021-01-02T12:00:00Z", |
| 74 | + "endTime": "2021-01-03T00:00:00Z" |
| 75 | + } |
| 76 | + }, |
| 77 | + "results": [] |
| 78 | +} |
| 79 | +``` |
| 80 | +* **resultId**: This is the information that you'll need to trigger **Get Batch Inference Results API**. |
| 81 | +* **status**: This indicates whether you trigger a batch inference task successfully. If you see **CREATED**, then you don't need to trigger this API again, you should use the **Get Batch Inference Results API** to get the detection status and anomaly results. |
| 82 | + |
| 83 | +## Get batch detection results |
| 84 | + |
| 85 | +There's no content in the request body, what's required only is to put the resultId in the API path, which will be in a format of: |
| 86 | +**{{endpoint}}anomalydetector/v1.1/multivariate/detect-batch/{{resultId}}** |
| 87 | + |
| 88 | +### Response |
| 89 | + |
| 90 | +A sample response: |
| 91 | + |
| 92 | +```json |
| 93 | +{ |
| 94 | + "resultId": "aaaaaaaa-5555-1111-85bb-36f8cdfb3365", |
| 95 | + "summary": { |
| 96 | + "status": "READY", |
| 97 | + "errors": [], |
| 98 | + "variableStates": [ |
| 99 | + { |
| 100 | + "variable": "series_0", |
| 101 | + "filledNARatio": 0.0, |
| 102 | + "effectiveCount": 721, |
| 103 | + "firstTimestamp": "2021-01-02T12:00:00Z", |
| 104 | + "lastTimestamp": "2021-01-03T00:00:00Z" |
| 105 | + }, |
| 106 | + { |
| 107 | + "variable": "series_1", |
| 108 | + "filledNARatio": 0.0, |
| 109 | + "effectiveCount": 721, |
| 110 | + "firstTimestamp": "2021-01-02T12:00:00Z", |
| 111 | + "lastTimestamp": "2021-01-03T00:00:00Z" |
| 112 | + }, |
| 113 | + { |
| 114 | + "variable": "series_2", |
| 115 | + "filledNARatio": 0.0, |
| 116 | + "effectiveCount": 721, |
| 117 | + "firstTimestamp": "2021-01-02T12:00:00Z", |
| 118 | + "lastTimestamp": "2021-01-03T00:00:00Z" |
| 119 | + }, |
| 120 | + { |
| 121 | + "variable": "series_3", |
| 122 | + "filledNARatio": 0.0, |
| 123 | + "effectiveCount": 721, |
| 124 | + "firstTimestamp": "2021-01-02T12:00:00Z", |
| 125 | + "lastTimestamp": "2021-01-03T00:00:00Z" |
| 126 | + }, |
| 127 | + { |
| 128 | + "variable": "series_4", |
| 129 | + "filledNARatio": 0.0, |
| 130 | + "effectiveCount": 721, |
| 131 | + "firstTimestamp": "2021-01-02T12:00:00Z", |
| 132 | + "lastTimestamp": "2021-01-03T00:00:00Z" |
| 133 | + } |
| 134 | + ], |
| 135 | + "setupInfo": { |
| 136 | + "dataSource": "https://mvaddataset.blob.core.windows.net/sample-onetable/sample_data_5_3000.csv", |
| 137 | + "topContributorCount": 3, |
| 138 | + "startTime": "2021-01-02T12:00:00Z", |
| 139 | + "endTime": "2021-01-03T00:00:00Z" |
| 140 | + } |
| 141 | + }, |
| 142 | + "results": [ |
| 143 | + { |
| 144 | + "timestamp": "2021-01-02T12:00:00Z", |
| 145 | + "value": { |
| 146 | + "isAnomaly": false, |
| 147 | + "severity": 0.0, |
| 148 | + "score": 0.3377174139022827, |
| 149 | + "interpretation": [] |
| 150 | + }, |
| 151 | + "errors": [] |
| 152 | + }, |
| 153 | + { |
| 154 | + "timestamp": "2021-01-02T12:01:00Z", |
| 155 | + "value": { |
| 156 | + "isAnomaly": false, |
| 157 | + "severity": 0.0, |
| 158 | + "score": 0.24631972312927247, |
| 159 | + "interpretation": [] |
| 160 | + }, |
| 161 | + "errors": [] |
| 162 | + }, |
| 163 | + { |
| 164 | + "timestamp": "2021-01-02T12:02:00Z", |
| 165 | + "value": { |
| 166 | + "isAnomaly": false, |
| 167 | + "severity": 0.0, |
| 168 | + "score": 0.16678125858306886, |
| 169 | + "interpretation": [] |
| 170 | + }, |
| 171 | + "errors": [] |
| 172 | + }, |
| 173 | + { |
| 174 | + "timestamp": "2021-01-02T12:03:00Z", |
| 175 | + "value": { |
| 176 | + "isAnomaly": false, |
| 177 | + "severity": 0.0, |
| 178 | + "score": 0.23783254623413086, |
| 179 | + "interpretation": [] |
| 180 | + }, |
| 181 | + "errors": [] |
| 182 | + }, |
| 183 | + { |
| 184 | + "timestamp": "2021-01-02T12:04:00Z", |
| 185 | + "value": { |
| 186 | + "isAnomaly": false, |
| 187 | + "severity": 0.0, |
| 188 | + "score": 0.24804904460906982, |
| 189 | + "interpretation": [] |
| 190 | + }, |
| 191 | + "errors": [] |
| 192 | + }, |
| 193 | + { |
| 194 | + "timestamp": "2021-01-02T12:05:00Z", |
| 195 | + "value": { |
| 196 | + "isAnomaly": false, |
| 197 | + "severity": 0.0, |
| 198 | + "score": 0.11487171649932862, |
| 199 | + "interpretation": [] |
| 200 | + }, |
| 201 | + "errors": [] |
| 202 | + }, |
| 203 | + { |
| 204 | + "timestamp": "2021-01-02T12:06:00Z", |
| 205 | + "value": { |
| 206 | + "isAnomaly": true, |
| 207 | + "severity": 0.32980116622958083, |
| 208 | + "score": 0.5666913509368896, |
| 209 | + "interpretation": [ |
| 210 | + { |
| 211 | + "variable": "series_2", |
| 212 | + "contributionScore": 0.4130149677604554, |
| 213 | + "correlationChanges": { |
| 214 | + "changedVariables": [ |
| 215 | + "series_0", |
| 216 | + "series_4", |
| 217 | + "series_3" |
| 218 | + ] |
| 219 | + } |
| 220 | + }, |
| 221 | + { |
| 222 | + "variable": "series_3", |
| 223 | + "contributionScore": 0.2993065960239115, |
| 224 | + "correlationChanges": { |
| 225 | + "changedVariables": [ |
| 226 | + "series_0", |
| 227 | + "series_4", |
| 228 | + "series_3" |
| 229 | + ] |
| 230 | + } |
| 231 | + }, |
| 232 | + { |
| 233 | + "variable": "series_1", |
| 234 | + "contributionScore": 0.287678436215633, |
| 235 | + "correlationChanges": { |
| 236 | + "changedVariables": [ |
| 237 | + "series_0", |
| 238 | + "series_4", |
| 239 | + "series_3" |
| 240 | + ] |
| 241 | + } |
| 242 | + } |
| 243 | + ] |
| 244 | + }, |
| 245 | + "errors": [] |
| 246 | + } |
| 247 | + ] |
| 248 | +} |
| 249 | +``` |
| 250 | + |
| 251 | +The response contains the result status, variable information, inference parameters, and inference results. |
| 252 | + |
| 253 | +* **variableStates**: This lists the information of each variable in the inference request. |
| 254 | +* **setupInfo**: This is the request body submitted for this inference. |
| 255 | +* **results**: This contains the detection results. There are three typical types of detection results. |
| 256 | + |
| 257 | +* Error code `InsufficientHistoricalData`. This usually happens only with the first few timestamps because the model inferences data in a window-based manner and it needs historical data to make a decision. For the first few timestamps, there's insufficient historical data, so inference can't be performed on them. In this case, the error message can be ignored. |
| 258 | + |
| 259 | +* **isAnomaly**: `false` indicates the current timestamp isn't an anomaly.`true` indicates an anomaly at the current timestamp. |
| 260 | + * `severity` indicates the relative severity of the anomaly and for abnormal data it's always greater than 0. |
| 261 | + * `score` is the raw output of the model on which the model makes a decision. `severity` is a derived value from `score`. Every data point has a `score`. |
| 262 | + |
| 263 | +* **interpretation**: This field only appears when a timestamp is detected as anomalous, which contains `variables`, `contributionScore`, `correlationChanges`. |
| 264 | + |
| 265 | +* **contributors**: This is a list containing the contribution score of each variable. Higher contribution scores indicate higher possibility of the root cause. This list is often used for interpreting anomalies and diagnosing the root causes. |
| 266 | + |
| 267 | +* **correlationChanges**: This field only appears when a timestamp is detected as anomalous, which included in interpretation. It contains `changedVariables` and `changedValues` that interpret which correlations between variables changed. |
| 268 | + |
| 269 | +* **changedVariables**: This field will show which variables that have significant change in correlation with `variable`. The variables in this list are ranked by the extent of correlation changes. |
| 270 | + |
| 271 | +> [!NOTE] |
| 272 | +> A common pitfall is taking all data points with `isAnomaly`=`true` as anomalies. That may end up with too many false positives. |
| 273 | +> You should use both `isAnomaly` and `severity` (or `score`) to sift out anomalies that are not severe and (optionally) use grouping to check the duration of the anomalies to suppress random noise. |
| 274 | +> Please refer to the [FAQ](../concepts/best-practices-multivariate.md#faq) in the best practices document for the difference between `severity` and `score`. |
| 275 | +
|
| 276 | +## Next steps |
| 277 | + |
| 278 | +* [Best practices of multivariate anomaly detection](../concepts/best-practices-multivariate.md) |
0 commit comments