From ce16e145938a8a595f7bc795852bc7394056017e Mon Sep 17 00:00:00 2001 From: Yoav Dobrin Date: Wed, 9 Feb 2022 16:15:34 +0200 Subject: [PATCH] fixing errors (location, legend, uri) --- ...ection with the Anomaly Detector API.ipynb | 25 ++++++++++--------- ...ection with the Anomaly Detector API.ipynb | 13 +++++----- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ipython-notebook/API Sample/Batch anomaly detection with the Anomaly Detector API.ipynb b/ipython-notebook/API Sample/Batch anomaly detection with the Anomaly Detector API.ipynb index f7a2bb7..5c2822f 100644 --- a/ipython-notebook/API Sample/Batch anomaly detection with the Anomaly Detector API.ipynb +++ b/ipython-notebook/API Sample/Batch anomaly detection with the Anomaly Detector API.ipynb @@ -76,7 +76,8 @@ "source": [ "def detect(endpoint, apikey, request_data):\n", " headers = {'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': apikey}\n", - " response = requests.post(endpoint, data=json.dumps(request_data), headers=headers)\n", + " endpoint_uri = f\"https://{endpoint}\"\n", + " response = requests.post(endpoint_uri, data=json.dumps(request_data), headers=headers)\n", " if response.status_code == 200:\n", " return json.loads(response.content.decode(\"utf-8\"))\n", " else:\n", @@ -92,9 +93,9 @@ "source": [ "def build_figure(sample_data, sensitivity):\n", " sample_data['sensitivity'] = sensitivity\n", - " result = detect(endpoint, apikey, sample_data)\n", - " columns = {'expectedValues': result['expectedValues'], 'isAnomaly': result['isAnomaly'], 'isNegativeAnomaly': result['isNegativeAnomaly'],\n", - " 'isPositiveAnomaly': result['isPositiveAnomaly'], 'upperMargins': result['upperMargins'], 'lowerMargins': result['lowerMargins'],\n", + " result = detect(endpoint_latest, apikey, sample_data)\n", + " columns = {'expectedValue': result['expectedValue'], 'isAnomaly': result['isAnomaly'], 'isNegativeAnomaly': result['isNegativeAnomaly'],\n", + " 'isPositiveAnomaly': result['isPositiveAnomaly'], 'upperMargin': result['upperMargin'], 'lowerMargin': result['lowerMargin'],\n", " 'timestamp': [parser.parse(x['timestamp']) for x in sample_data['series']], \n", " 'value': [x['value'] for x in sample_data['series']]}\n", " response = pd.DataFrame(data=columns)\n", @@ -106,19 +107,19 @@ " anomaly_indexes = []\n", " p = figure(x_axis_type='datetime', title=\"Batch Anomaly Detection ({0} Sensitvity)\".format(sensitivity), width=800, height=600)\n", " for anom in response['isAnomaly']:\n", - " if anom == True and (values[index] > response.iloc[index]['expectedValues'] + response.iloc[index]['upperMargins'] or \n", - " values[index] < response.iloc[index]['expectedValues'] - response.iloc[index]['lowerMargins']):\n", + " if anom == True and (values[index] > response.iloc[index]['expectedValue'] + response.iloc[index]['upperMargin'] or \n", + " values[index] < response.iloc[index]['expectedValue'] - response.iloc[index]['lowerMargin']):\n", " anomalies.append(values[index])\n", " anomaly_labels.append(label[index])\n", " anomaly_indexes.append(index)\n", " index = index+1\n", - " upperband = response['expectedValues'] + response['upperMargins']\n", - " lowerband = response['expectedValues'] -response['lowerMargins']\n", + " upperband = response['expectedValue'] + response['upperMargin']\n", + " lowerband = response['expectedValue'] -response['lowerMargin']\n", " band_x = np.append(label, label[::-1])\n", " band_y = np.append(lowerband, upperband[::-1])\n", " boundary = p.patch(band_x, band_y, color=Blues4[2], fill_alpha=0.5, line_width=1, legend='Boundary')\n", " p.line(label, values, legend='Value', color=\"#2222aa\", line_width=1)\n", - " p.line(label, response['expectedValues'], legend='ExpectedValue', line_width=1, line_dash=\"dotdash\", line_color='olivedrab')\n", + " p.line(label, response['expectedValue'], legend='ExpectedValue', line_width=1, line_dash=\"dotdash\", line_color='olivedrab')\n", " anom_source = ColumnDataSource(dict(x=anomaly_labels, y=anomalies))\n", " anoms = p.circle('x', 'y', size=5, color='tomato', source=anom_source)\n", " p.legend.border_line_width = 1\n", @@ -149,7 +150,7 @@ "outputs": [], "source": [ "# Hourly Sample\n", - "sample_data = json.load(open('univariate_sample_hourly.json'))\n", + "sample_data = json.load(open('../SDK Sample/univariate_sample_hourly.json'))\n", "sample_data['granularity'] = 'hourly'\n", "sample_data['period'] = 24\n", "# 95 sensitivity\n", @@ -190,7 +191,7 @@ "outputs": [], "source": [ "#daily sample\n", - "sample_data = json.load(open('univariate_sample_daily.json'))\n", + "sample_data = json.load(open('../SDK Sample/univariate_sample_daily.json'))\n", "sample_data['granularity'] = 'daily'\n", "# 95 sensitivity\n", "build_figure(sample_data,95)" @@ -238,4 +239,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/ipython-notebook/API Sample/Latest point detection with the Anomaly Detector API.ipynb b/ipython-notebook/API Sample/Latest point detection with the Anomaly Detector API.ipynb index 81620ba..d6dbf31 100644 --- a/ipython-notebook/API Sample/Latest point detection with the Anomaly Detector API.ipynb +++ b/ipython-notebook/API Sample/Latest point detection with the Anomaly Detector API.ipynb @@ -80,7 +80,8 @@ "source": [ "def detect(endpoint, apikey, request_data):\n", " headers = {'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': apikey}\n", - " response = requests.post(endpoint, data=json.dumps(request_data), headers=headers)\n", + " endpoint_uri = f\"https://{endpoint}\"\n", + " response = requests.post(endpoint_uri, data=json.dumps(request_data), headers=headers)\n", " if response.status_code == 200:\n", " return json.loads(response.content.decode(\"utf-8\"))\n", " else:\n", @@ -117,9 +118,9 @@ " lowerband = response['expectedValues'] -response['lowerMargins']\n", " band_x = np.append(label, label[::-1])\n", " band_y = np.append(lowerband, upperband[::-1])\n", - " boundary = p.patch(band_x, band_y, color=Blues4[2], fill_alpha=0.5, line_width=1, legend='Boundary')\n", - " p.line(label, values, legend='value', color=\"#2222aa\", line_width=1)\n", - " p.line(label, response['expectedValues'], legend='expectedValue', line_width=1, line_dash=\"dotdash\", line_color='olivedrab')\n", + " boundary = p.patch(band_x, band_y, color=Blues4[2], fill_alpha=0.5, line_width=1, legend_label='Boundary')\n", + " p.line(label, values, legend_label='value', color=\"#2222aa\", line_width=1)\n", + " p.line(label, response['expectedValues'], legend_label='expectedValue', line_width=1, line_dash=\"dotdash\", line_color='olivedrab')\n", " anom_source = ColumnDataSource(dict(x=anomaly_labels, y=anomalies))\n", " anoms = p.circle('x', 'y', size=5, color='tomato', source=anom_source)\n", " p.legend.border_line_width = 1\n", @@ -148,7 +149,7 @@ "outputs": [], "source": [ "def detect_anomaly(sensitivity):\n", - " sample_data = json.load(open('univariate_sample_daily.json'))\n", + " sample_data = json.load(open('../SDK Sample/univariate_sample_daily.json'))\n", " points = sample_data['series']\n", " skip_point = 29\n", " result = {'expectedValues': [None]*len(points), 'upperMargins': [None]*len(points), \n", @@ -217,4 +218,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +}