Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Anomalies Quick Start
# Depends on Python3
# Add your Nexosis api key before executing
apiKey="YOUR API KEY HERE"
baseUrl="https://ml.nexosis.com/v1"
curl -s -H "api-key: $apiKey" -X POST "$baseUrl/imports/url" \
-H "Content-Type: application/json" \
-d '{"dataSetName":"cardio","url":"https://raw.githubusercontent.com/Nexosis/sampledata/master/cardio.json"}'
sleep 10s
sessionId=$(curl -s -H "api-key: $apiKey" -X POST "$baseUrl/sessions/model" \
-H "Content-Type: application/json" \
-d '{"dataSourceName": "cardio", "predictionDomain": "anomalies"}' | python3 -c "import sys, json; print(json.load(sys.stdin)['sessionId'])")
status=$(curl -H "api-key: $apiKey" $baseUrl/sessions/$sessionId | python3 -c "import sys, json; print(json.load(sys.stdin)['status'])")
while [ "$status" != "completed" ]
do
status=$(curl -H "api-key: $apiKey" $baseUrl/sessions/$sessionId | python3 -c "import sys, json; print(json.load(sys.stdin)['status'])")
sleep 10s
done
modelId=$(curl -H "api-key: $apiKey" $baseUrl/sessions/$sessionId/results | python3 -c "import sys, json; print(json.load(sys.stdin)['modelId'])")
# printing results by key...
curl -s -H "api-key: $apiKey" $baseUrl/sessions/$sessionId/results | python3 -c "import sys, json;json_resp=json.load(sys.stdin);x=[print(d['key'] + ' : ' + d['anomaly']) for d in json_resp['data']]"
# testing whether or not an observed set of values is an anomaly...
curl -s -H "api-key: $apiKey" -X POST $baseUrl/models/$modelId/predict \
-H "Content-Type: application/json" \
-d '{ "data": [{"X.1": -1.15907509242824,"X.2": -0.91998843744384,"X.3": -0.178808273342188,"X.4": 0.0119005653086114,"X.5": 3.14482390535516,"X.6": 17.314053637174,"X.7": -0.278294946006147,"X.8": 1.28100338235996,"X.9": 0.759072460103087,"X.10": -0.420487347915062,"X.11": -1.39808792464813,"X.12": 0.744634905731968,"X.13": -1.26165666571131,"X.14": -0.400329665815939,"X.15": 0.278624569020388,"X.16": 0.963082541396573,"X.17": -4.14708829524105,"X.18": -3.19083518334924,"X.19": -3.21686477340904,"X.20": 2.58264294083969,"X.21": -2.12660546680886,"key": 1780}]}' | python3 -c "import sys, json; print(json.load(sys.stdin)['data'][0]['anomaly'])"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment