Anomaly Detection Quickstart
Learn how to use the Brainrex anomaly detection API in Python.
Welcome to the Anomaly Detection Quickstart Guide for the Brainrex API in Python! In this guide, you'll learn how to easily incorporate advanced time-series anomaly detection capabilities into your Python applications using the Brainrex API. With our API, you can quickly identify and resolve issues by analyzing time-series data of various types, utilizing the best anomaly detection algorithm customized to your particular dataset, ensuring unmatched precision. This guide will walk you through the steps of setting up your environment, making requests to the API, and visualizing the results. By the end of this guide, you'll have a solid understanding of how to use the Brainrex API for anomaly detection in Python and be ready to integrate it into your own applications. Let's get started!
Install the Brainrex library
pip install brainrex
Import the brainrex library and authentificate
from __future__ import print_function
import time
from pprint import pprint
import pandas as pd
import brainrex
from brainrex.rest import ApiException
# Configure API key authorization: APIKeyHeader
configuration = brainrex.Configuration()
configuration.api_key['x-api-key'] = 'INSERT_API_KEY_HERE'
##create an instance of the API class
api_instance = brainrex.AnomalyApi(brainrex.ApiClient(configuration))
Download sample data
Download the examples Time Series data we provide. This dataset was extracted from the Coinbase PRO exchange using the Integrations API.
TIME_SERIES_DATA_PATH="https://s3-eu-west-1.amazonaws.com/brainrex.com/data/request-data.csv"
Build the PointTimeSeries object
from brainrex.models import PointTimeSeries
series = []
data_file = pd.read_csv(TIME_SERIES_DATA_PATH, header=None, encoding='utf-8', parse_dates=[0])
for index, row in data_file.iterrows():
series.append(brainrex.PointTimeSeries(timestamp=row[0], value=row[1]))
Call the API
request = brainrex.TimeSeries() # TimeSeries | Time Series to be analyzed, with the following format. (optional)
try:
# Detects anomaly in historical data
api_response = api_instance.anomaly_batch(request=series)
pprint(api_response)
except ApiException as e:
print("Exception when calling AnomalyApi->anomaly_batch: %s\n" % e)