Last active
January 12, 2018 16:06
-
-
Save nexosisops/f328d588b0238b50c54260392d1a82b5 to your computer and use it in GitHub Desktop.
Anomalies Quick Start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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